class - PHP: Get static method reference -
i want reference of static method static method in same class, php interprets 2 lines (see example code below) access constant. not possible reference static methods in php?
class foo { public static function test() { self::bar(); // calling (not referencing) works $bar_reference = self::bar; // error: undefined class constant 'bar' } public static function bar() { echo "hello"; } } foo::test(); $bar_reference = foo::bar; // error: undefined class constant
just clarify again: not want call static method - want reference it.
you can create callable this:
class foo { public static function test() { $bar_reference = array(__class__, 'bar'); // call $bar_reference(); } public static function bar() { echo "hello"; } } foo::test(); $bar_reference = foo::bar();
Comments
Post a Comment