note 107564 added to language.functions
| From: | Anonymous | Date: | Fri, 17 Feb 2012 15:31:05 +0000 |
| Subject: | note 107564 added to language.functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186197@lists.php.net to get a copy of this message | ||
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()
?>
----
Server IP: 69.147.83.197
Probable Submitter: 72.219.151.91
----
Manual Page -- http://www.php.net/manual/en/language.functions.php
Edit -- https://master.php.net/note/edit/107564
Del: integrated -- https://master.php.net/note/delete/107564/integrated
Del: useless -- https://master.php.net/note/delete/107564/useless
Del: bad code -- https://master.php.net/note/delete/107564/bad+code
Del: spam -- https://master.php.net/note/delete/107564/spam
Del: non-english -- https://master.php.net/note/delete/107564/non-english
Del: in docs -- https://master.php.net/note/delete/107564/in+docs
Del: other reasons-- https://master.php.net/note/delete/107564
Reject -- https://master.php.net/note/reject/107564
Search -- https://master.php.net/manage/user-notes.php