#30716 [Com]: Dynamic Static Member Access
ID: 30716
Comment by: joscha at feth dot com
Reported By: jake at development dot mindvision dot com dot au
Status: Open
Bug Type: Feature/Change Request
Operating System: Gentoo Linux (2.4.x)
PHP Version: 5.0.1
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[2004-11-08 05:59:14] jake at development dot mindvision dot com dot au
Description:
------------
Hello,
I feel i have a syntax bug or unclear syntax limitation.
I am trying to access static members of classes, dynamically
ie $foo = 'className'; echo $foo::$staticVariable;
For more information please see my posts on the php-generals list
- http://news.php.net/php.general/201458
Thanks in advance
Yours Sincerely
Jake Press
Reproduce code:
---------------
<?php
// Define a class with a nice juicy static variable
class bob {
public static $type = 'safd';
}
// Lets chuck the name of the class into a variable...
$foo = 'bob';
// Just to show it all works lets do it manualllllly
echo bob::$type;
// This is the line with the well-wicked parse error on the
double colon
echo $foo::$type;
?>
Expected result:
----------------
safdsafd
Actual result:
--------------
Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting
',' or ';' in /mnt/data0/www/twd/test.php on line 15
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30716&edit=1
Thread (8 messages)