note 107564 deleted from language.functions by danbrown

From: Date: Thu, 10 May 2012 20:43:27 +0000
Subject: note 107564 deleted from language.functions by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187828@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- Regarding [Jakob Thomsen 26-Feb-2008 12:57]; below is are two modifications to your code: (1) "As of PHP 5.3.0, it's possible to reference the class using a variable."( http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php ) ; however, you still cannot reference a static function using a variable; and (2) there does seem to be a workaround using eval (that I can't explain, perhaps another can enlighten us): <?php class foo { public static function bar(){ return "bar in a class called"; } } function bar() { return "normal bar called"; } $strFN = "bar"; echo $strFN(); // => "normal bar called" $strCL = "foo"; echo $strCL::bar(); // (1) As of 5.3.0 => "bar in a class called" $strFN2 = "foo::bar"; eval('$x = ' . 'foo::' . '$strFN();'); // (2) eval works for variable static function name echo $x; // => "bar in a class called" echo $strFN2(); // Fatal error: Call to undefined function foo::bar() ?>

« previous php.notes (#187828) next »