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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -