dongya2029 2017-09-22 23:53
浏览 22
已采纳

调用函数时的函数错误

I have this error :

Warning: usort() expects parameter 2 to be a valid callback, function 'sortSecmModules' not found or invalid function name 

How to resolve, an idea ?

Thank you.

I have a file called SecurityCheck like this

  namespace \Apps\Tools\SecurityCheck\Sites\Admin\Pages\Home\Actions;

  use Core\OM\Registry;

  class SecurityCheck extends \Core\OM\PagesActionsAbstract {
    public function execute() {
      $OSCOM_SecurityCheck = Registry::get('SecurityCheck');

      $this->page->setFile('security_check.php');

      $OSCOM_SecurityCheck->loadDefinitions('Sites/ClicShoppingAdmin/main');
    }

    public function sortSecmModules($a, $b) {
      return strcasecmp($a['title'], $b['title']);
    }
  }

and another file security_check.php with this elements inside :

  usort($modules, 'sortSecmModules');
  • 写回答

1条回答 默认 最新

  • dongxia2068 2017-09-22 23:57
    关注

    sortSecmModules is a class method, you need to include the class name.

    usort($modules, 'SecurityCheck::sortSecmModules');
    

    But you also need to make it a static function, so it doesn't have to be called through an object.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?