|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-07-07 08:56 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 17:00:01 2025 UTC |
Description: ------------ I noticed a limitation in (at least) latest version of php. It's impossible to iterate the const or static member of a class. The only possible (but REALY too hard) whould be to use the reflector propriety. I don't know if it's a feature to add or a missing explanation in documentation. But if it's not supported at all, it should be reported as a lack of feature in documentation and scheduled for php6 ? Reproduce code: --------------- <?php //The class class someclass { //The constant const someconst = 'somevalue'; //The public static member public static $somepublicstatic = 'somevalue'; //The protected static member protected static $someprotectedstatic = 'somevalue'; //The private static member private static $someprivatestatic = 'somevalue'; //A function to list static or const members public static function somefunction() { //Try to iterate const or static member foreach(self as $key => $value) echo "$key = $value\n"; } } echo "static function list:\n"; someclass::somefunction(); echo "external list:\n"; foreach(someclass as $key => $value) echo "$key = $value\n"; ?> Expected result: ---------------- static function list: someconst = somevalue somepublicstatic = somevalue someprotectedstatic = somevalue someprivatestatic = somevalue external list: someconst = somevalue somepublicstatic = somevalue Actual result: -------------- static function list: PHP Notice: Use of undefined constant self - assumed 'self' in /var/www/web/test.php on line 17 Notice: Use of undefined constant self - assumed 'self' in /var/www/web/test.php on line 17 PHP Warning: Invalid argument supplied for foreach() in /var/www/web/test.php on line 17 Warning: Invalid argument supplied for foreach() in /var/www/web/test.php on line 17 external list: PHP Notice: Use of undefined constant someclass - assumed 'someclass' in /var/www/web/test.php on line 25 Notice: Use of undefined constant someclass - assumed 'someclass' in /var/www/web/test.php on line 25 PHP Warning: Invalid argument supplied for foreach() in /var/www/web/test.php on line 25 Warning: Invalid argument supplied for foreach() in /var/www/web/test.php on line 25