From: adove at booyahnetworks dot com Operating system: WinXP PHP version: 5.0.3 PHP Bug Type: Zend Engine 2 problem Bug description: Accessing overloaded member via foreach does not work
Description: ------------ Using an overloaded property from an object instance directly in a foreach fails. If you assign the property (or a reference to it) to a variable first it works fine. This is reproducable. Interestingly enough, I see a strange problem with inheritance and overloaded members. I am unable to reproduce it in a simple example. I will continue to work that. Basically, you get the same fatal error as here BUT on assignment to a member variable of the parent class that is not overloaded. It's bizzare. As soon as I remove the __get/__set from the child, the parent method works fine again from an instance of child. Again, simple examples do not seem to reproduce. <sigh> Reproduce code: --------------- class Son { protected $m_aActions; function __construct(&$aActions) { $this->m_aActions = $aActions; } function __get($mName) { $mRetval = null; switch($mName) { case("Actions"): { $mRetval = $this->m_aActions; break; } } return $mRetval; } } $aActions = array("add", "delete"); $oSon = new Son($aActions); $aActions = $oSon->Actions; var_dump($aActions); foreach($oSon->Actions as $strAction) { echo $strAction . "\n"; } Expected result: ---------------- array(2) { [0]=> string(3) "add" [1]=> string(6) "delete" } add delete Actual result: -------------- array(2) { [0]=> string(3) "add" [1]=> string(6) "delete" } Fatal error: Cannot access undefined property for object with overloaded property access -- Edit bug report at http://bugs.php.net/?id=31976&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31976&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31976&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31976&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=31976&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=31976&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=31976&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=31976&r=needscript Try newer version: http://bugs.php.net/fix.php?id=31976&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=31976&r=support Expected behavior: http://bugs.php.net/fix.php?id=31976&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=31976&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=31976&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=31976&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31976&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=31976&r=dst IIS Stability: http://bugs.php.net/fix.php?id=31976&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=31976&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=31976&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=31976&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=31976&r=mysqlcfg