Re: Syntax problem - dynamic static member access
| From: | M. Sokolewicz | Date: | Sun, 07 Nov 2004 09:38:01 +0000 |
| Subject: | Re: Syntax problem - dynamic static member access | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-201410@lists.php.net to get a copy of this message | ||
hi,
it's a limitation, and not allowed in PHP. There was a whole line of posts about it in internals.
- Tul
Jake Press wrote:
Hello All, I am having an interesting syntax problem. :( I have been battling this little bugger for the last week and a half, I have exhausted google and numerous php channels in that time. I am starting to beleive it could be a syntax that is sofar un-documented or an unclear syntax limitation (read as: bug?). PHP Version: ------------ PHP Version 5.1.0-dev - And has been tested on numerous other builds/versions Problem: -------- I am trying to access a static member of a class dynamically. ie. $foo = 'className'; echo $foo::$staticMember; Example Code: ------------- <?php// Define a class with a nice juicy static variableclass 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 manuallllllyecho bob::$type;// This is the line with the well-wicked parse error on the double colonecho $foo::$type;?>Note that the last line in this example code generated a syntax error: Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting ',' or ';' in /mnt/data0/www/twd/test.php on line 15 I'm aware that the current syntax is definately wrong, but for simplicity i think its a good example. I think i have ruled out its an internal scoping issue within php by successfully using eval() to them same effect. ie. eval('echo '. $foo .'::$type;'); Thanks in advance for any Thoughts, Answers and Comments Regards Jake Press