|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-02-15 10:39 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 16:00:01 2025 UTC |
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