Edit report at http://bugs.php.net/bug.php?id=30716&edit=1
ID: 30716 Updated by: [email protected] Reported by: jake at development dot mindvision dot com dot au Summary: Dynamic Static Member Access -Status: Open +Status: Closed Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues Operating System: Gentoo Linux (2.4.x) PHP Version: 5.0.1 -Assigned To: +Assigned To: johannes Block user comment: N Private report: N New Comment: "Dynamic static calls" were added in PHP 5.3.0 Previous Comments: ------------------------------------------------------------------------ [2007-10-05 01:45:25] itisben at gmail dot com Hi, In case anyone is still beating their head against the wall -or- doesn't want to use eval -or- isn't sure whether or not 5.2.4 fixed this in addition to the dynamic static method call that was supposed to be fixed in that version - http://bugs.php.net/bug.php?id=31318 (I can't get it to work after moving to that version, unless the little note at the bottom means that it is 5.3). Anway, here it is - it requires PHP >=5 for the Reflection <?php ... $refClass = new ReflectionClass($className); $staticMemVal = $refClass->getStaticPropertyValue($staticMemName); ... ?> Hopefully the variable names are descriptive enough to get the general idea. Thanks, Ben ------------------------------------------------------------------------ [2005-12-21 00:23:58] jake at press dot id dot au Heyas I havent got a copy of php infront of me, and it has been many months since i last poked around on this issue - so apologies if i am wrong... But i dont beleive "call_user_func()" is the solution. ... we are trying too access a static member dynamically, not a static method. Such a pity, i have been successfully using a workaround along the same lines as suggested by joscha at feth dot com for along time now, i was hoping i could go thru and fix all of my code that is dependant on it by now :( I'll try and find some time too investigate this further and attempt to fix - but i fear that will be closer to this time next year. Jake Press ------------------------------------------------------------------------ [2004-11-11 09:54:49] [email protected] use call_user_func() for that. ------------------------------------------------------------------------ [2004-11-11 09:22:32] joscha at feth dot com After I found out, that my note (http://news.php.net/php.notes/78312) was deleted, which I thought was not a good idea, because it is the only way to make a static function call to a "unknown" class, I wrote a Mail to the guy who deleted it. After a few mails we decided that the code I wrote in the note: print_r(eval("return $classname::getBla();")); is completely correct and working. So I resubmitted my note, but I also think it'd be better to allow $classname::getBla(); out-of-the-box as the eval call is always a performance killer and it restricts the use of the code above to examples where no user-input is in $classname. ------------------------------------------------------------------------ [2004-11-09 09:27:15] k at ailis dot de Just for info: The problem is also present in latest CVS. And even if it is not a bug it's still a useful feature request. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/bug.php?id=30716 -- Edit this bug report at http://bugs.php.net/bug.php?id=30716&edit=1
