maegeri
maegeri

Reputation: 5

function error when a function is called

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');

Upvotes: 0

Views: 22

Answers (1)

Barmar
Barmar

Reputation: 780909

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.

Upvotes: 3

Related Questions