Using called in php

I am trying to imitate the built-in function definition of the usr function in my implementation below:

class heapSort { static function hsort(array &$array, callable $cmp_function){ // logic } } class utility{ static function mycomparator(){ // logic } } $array = array(5,3,8,1); $callback = array('utility','mycomparator'); heapSort::hsort($array, $callback); 

While the $callback variable is "callable", why am I getting below a fatal error?

Argument 2 passed to heapSort :: hsort () must be an instance of the called.

In particular, how do I make / typecast a $variable to call?

+4
source share
1 answer

callable supported only PHP 5.4 try instead of is_callable

 static function hsort(array &$array, $cmp_function) { if (! is_callable($cmp_function)) throw new InvalidArgumentException("Function not callable"); } 
+4
source

All Articles