我有一个使用Symfony用PHP编写的Web应用程序,我将它从本地计算机移动到远程服务器。当我尝试登录时出现错误:
致命错误:AdminUserRole :: getAccessibleEmployeeIds()的声明必须与AbstractUserRole :: getAccessibleEmployeeIds()的声明兼容
AdminUserRole类
class AdminUserRole extends AbstractUserRole {
public function getAccessibleEmployeeIds($operation = null, $returnType = null, $requiredPermissions = array()) {
return $this->getEmployeeService()->getEmployeeIdList(false);
}
public function getAccessibleEmployeePropertyList($properties, $orderField, $orderBy, $requiredPermissions = array()) {
return $this->getEmployeeService()->getEmployeePropertyList($properties, $orderField, $orderBy, false);
}
public function getAccessibleEmployees($operation = null, $returnType = null, $requiredPermissions = array()) {
$employees = $this->getEmployeeService()->getEmployeeList('empNumber', 'ASC', true);
$employeesWithIds = array();
foreach ($employees as $employee) {
$employeesWithIds[$employee->getEmpNumber()] = $employee;
}
return $employeesWithIds;
}
public function getAccessibleLocationIds($operation, $returnType) {
$locations = $this->getLocationService()->getLocationList();
$ids = array();
foreach ($locations as $location) {
$ids[] = $location->getId();
}
return $ids;
}
public function getAccessibleOperationalCountryIds($operation, $returnType) {
$operationalCountries = $this->getOperationalCountryService()->getOperationalCountryList();
$ids = array();
foreach ($operationalCountries as $country) {
$ids[] = $country->getId();
}
return $ids;
}
public function getAccessibleSystemUserIds($operation, $returnType) {
return $this->getSystemUserService()->getSystemUserIdList();
}
public function getAccessibleUserRoleIds($operation, $returnType) {
$userRoles = $this->getSystemUserService()->getAssignableUserRoles();
$ids = array();
foreach ($userRoles as $role) {
$ids[] = $role->getId();
}
return $ids;
}
}
我的抽象类
abstract class AbstractUserRole {
protected $employeeService;
protected $systemUserService;
protected $operationalCountryService;
protected $locationService;
protected $userRoleManager;
protected $roleName;
public function __construct($roleName, $userRoleManager) {
$this->userRoleManager = $userRoleManager;
$this->roleName = $roleName;
}
public function getSystemUserService() {
if (empty($this->systemUserService)) {
$this->systemUserService = new SystemUserService();
}
return $this->systemUserService;
}
public function setSystemUserService($systemUserService) {
$this->systemUserService = $systemUserService;
}
public function getEmployeeService() {
if (empty($this->employeeService)) {
$this->employeeService = new EmployeeService();
}
return $this->employeeService;
}
public function setEmployeeService($employeeService) {
$this->employeeService = $employeeService;
}
public function getLocationService() {
if (empty($this->locationService)) {
$this->locationService = new LocationService();
}
return $this->locationService;
}
public function setLocationService($locationService) {
$this->locationService = $locationService;
}
public function getOperationalCountryService() {
if (empty($this->operationalCountryService)) {
$this->operationalCountryService = new OperationalCountryService();
}
return $this->operationalCountryService;
}
public function setOperationalCountryService($operationalCountryService) {
$this->operationalCountryService = $operationalCountryService;
}
public function getAccessibleEntities($entityType, $operation = null, $returnType = null, $requiredPermissions = array()) {
switch ($entityType) {
case 'Employee':
$entities = $this->getAccessibleEmployees($operation, $returnType, $requiredPermissions);
break;
}
return $entities;
}
public function getAccessibleEntityProperties($entityType, $properties = array(), $orderField = null, $orderBy = null, $requiredPermissions = array()) {
switch ($entityType) {
case 'Employee':
$propertyList = $this->getAccessibleEmployeePropertyList($properties, $orderField, $orderBy, $requiredPermissions);
break;
}
return $propertyList;
}
public function getAccessibleEntityIds($entityType, $operation = null, $returnType = null, $requiredPermissions = array()) {
switch ($entityType) {
case 'Employee':
$ids = $this->getAccessibleEmployeeIds($operation, $returnType, $requiredPermissions);
break;
case 'SystemUser':
$ids = $this->getAccessibleSystemUserIds($operation, $returnType);
break;
case 'OperationalCountry':
$ids = $this->getAccessibleOperationalCountryIds($operation, $returnType);
break;
case 'UserRole':
$ids = $this->getAccessibleUserRoleIds($operation, $returnType);
break;
case 'Location':
$ids = $this->getAccessibleLocationIds($operation, $returnType);
break;
}
return $ids;
}
public abstract function getAccessibleEmployees($operation = null, $returnType = null, $requiredPermissions = array());
public abstract function getAccessibleEmployeePropertyList($properties, $orderField, $orderBy, $requiredPermissions = array());
public abstract function getAccessibleEmployeeIds($operation, $returnType, $requiredPermissions = array());
public abstract function getAccessibleSystemUserIds($operation, $returnType);
public abstract function getAccessibleOperationalCountryIds($operation, $returnType);
public abstract function getAccessibleUserRoleIds($operation, $returnType);
public abstract function getAccessibleLocationIds($operation, $returnType);
}
答案 0 :(得分:3)
嗯,这两个功能签名不兼容。
abstract public function getAccessibleEmployeeIds($operation, $returnType, $requiredPermissions = array());
public function getAccessibleEmployeeIds($operation = null, $returnType = null, $requiredPermissions = array()) {
abstract
函数至少需要两个参数,而您的实现可以不带参数调用。这不是同一个签名。删除null
默认值。
答案 1 :(得分:0)
您的方法声明是
public abstract function getAccessibleEmployeeIds($operation, $returnType, $requiredPermissions = array());
但实际的实现是
public function getAccessibleEmployeeIds($operation = null, $returnType = null, $requiredPermissions = array());
如您所见,原始声明至少需要2个参数,但您的实现突然说不需要任何参数。
您可能在服务器上使用PHP启用了严格模式,或者只安装了更严格规则集的新版本,这使得实现与声明完全相同。
只需将AdminUserRole.php
中的代码更改为
public function getAccessibleEmployeeIds($operation, $returnType, $requiredPermissions = array())
{
return $this->getEmployeeService()->getEmployeeIdList(false);
}
你会没事的。