From: robin at soal dot org Operating system: Windows PHP version: 5CVS-2007-07-08 (snap) PHP Bug Type: Scripting Engine problem Bug description: Foreach on object does not iterate over all visible properties
Description: ------------ The documentation states that "all visible properties will be used for the iteration" when foreach'ing over an object. Below is a case where this is not true. Reproduce code: --------------- <?php class C { private $priv = "A private variable"; function doLoop() { echo "Proof that the private is visible: " . $this->priv . "\n"; foreach ($this as $k=>$v) { echo "The private is visible so should be accessed in the loop:\n"; echo "-> $k: $v"; } } } class D extends C {} $myD = new D; $myD->doLoop(); ?> Expected result: ---------------- Proof that the private is visible: A private variable The private is visible so should be accessed in the loop: -> priv: A private variable Actual result: -------------- Proof that the private is visible: A private variable -- Edit bug report at http://bugs.php.net/?id=41929&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41929&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41929&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41929&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41929&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41929&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41929&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41929&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41929&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41929&r=support Expected behavior: http://bugs.php.net/fix.php?id=41929&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41929&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41929&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41929&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41929&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41929&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41929&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41929&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41929&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41929&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41929&r=mysqlcfg