1

我有一个使用 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);    

}

4

2 回答 2

3

好吧,这两个函数签名不兼容。

abstract public function getAccessibleEmployeeIds($operation, $returnType, $requiredPermissions = array());
         public function getAccessibleEmployeeIds($operation = null, $returnType = null, $requiredPermissions = array()) {

abstract函数至少需要两个参数,而您的实现可以在没有参数的情况下调用。那不是同一个签名。删除null默认值。

于 2012-11-21T10:10:06.550 回答
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);
}

你会没事的。

于 2012-11-21T10:15:05.963 回答