Is there any way to assign a static function to a variable, or accomplishing this in some other way?
class my_class{
public static function my_method($a){
return $a;
}
}
$some_func = my_class::my_method;
$someAnonFunc = function($a) use ($some_func){
return $some_func($a);
}
$inst = new SomeOtherClass(); //Defined somewhere else, in some other file
$inst->someMethod($a, $someAnonFunc);
At this point, I get:
Fatal error: Undefined class constant ‘my_method’
Functions are not first class in PHP .. strings are. You would have to use
call_user_funcif you wanted to stick with the::syntax as one unit:Trying to run
$some_func()will not work since it will treat the colons as part of the function name.