From: rapsys at free dot fr
Operating system: Mandriva Linux 2007 (Cooker)
PHP version: 5.1.4
PHP Bug Type: Feature/Change Request
Bug description: Enable possibility to iterate static or const member in class
with foreach
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
--
Edit bug report at http://bugs.php.net/?id=38028&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=38028&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=38028&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=38028&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=38028&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=38028&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=38028&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=38028&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=38028&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=38028&r=support
Expected behavior: http://bugs.php.net/fix.php?id=38028&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=38028&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=38028&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=38028&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38028&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=38028&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=38028&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=38028&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=38028&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=38028&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=38028&r=mysqlcfg