The only alternative I could find on @nickb is something that I have never heard of, but hey, this is for SO!
I found ReflectionMethod , which seems more bloated than call_user_func , but was the only alternative way I can find:
<?php class Car{ public static function a(){ return 'hi'; } } class Constants{ public static $use='Car'; } $reflectionMethod = new ReflectionMethod(Constants::$use, 'a'); echo $reflectionMethod->invoke(new Car());
The above result is an unsuccessful experiment because Casebash does not want to create temporary variables.
As CORRUPT mentioned in the comments, the following can be used, although it has been tested with PHP version 5.4.14 (which I cannot do):
echo (new ReflectionMethod(Constants::$use, 'a'))->invoke(new Car());
source share