ID: 39449 Comment by: tim dot pickup at gmail dot com Reported By: pstradomski at gmail dot com Status: Assigned Bug Type: Scripting Engine problem Operating System: Linux PHP Version: 5.2.0 Assigned To: dmitry New Comment:
Just adding a comment to say this "feature" is also going to cause me a lot of pain changing code. Any reason it is "expected behaviour" or do we just get a 4 word reply basically saying **** you ? Previous Comments: ------------------------------------------------------------------------ [2006-12-15 19:32:06] davidm at marketo dot com I agree strongly with brjann's analysis. Once the language allows overloaded properties on an object, it's completely confusing to say that overloaded array properties are immutable while all other property types are mutable, and also that non-overloaded array properties can be iterated with foreach but overloaded array properties cannot be iterated. I've got a significant amount of code that will have to be rewritten because of this change. The symfony framework encourages a design pattern that uses overloaded properties on the action objects and any instances where the overloaded property is an array are now broken. Other symfony users have run into the problem as well (http://www.symfony-project.com/forum/index.php/m/15684/#msg_15684). David Morandi ------------------------------------------------------------------------ [2006-12-06 22:18:09] mail at peter-thomassen dot de I do agree with Denis in the sense that one should disable the notice for read access (using foreach, p.ex.), until a global solution including write access is found (or not). This doesn't harm anyone and would save me some lines of error_reporting() changes. Thanks! ------------------------------------------------------------------------ [2006-12-06 11:08:10] brjann at gmail dot com "// This should not raise notice foreach( $a->overloaded_property as $val ) echo $val."<br />\n"; // This should raise notice $a->overloaded_property[] = 6;" I do not agree with that. Neither of the examples should raise a notice. There is no reason for $a->overloadedprop = $bar to work, but not $a->overloadedprop[$foo] = $bar or foreach($a->overloadedprop){} Either properties can be overloaded and therefore read, assigned and iterated over, or not. Overloaded properties should behave the same way as ordinary properties, or else the object's behaviour is unpredictable. Perhaps the solution of using __get() to return a reference is unsatisfactory in some way, but the behaviour should still be there. /Brjánn ------------------------------------------------------------------------ [2006-12-04 08:55:15] denis at edistar dot com I think the warning should be raised only when someone is trying to write the overloaded property. Foreach and other loop constructs are readonly constructs except when they are using references of the overloaded properties. For example: <?php class A{ private $test = array(1,2,3,4,5); public function __get($v){ return $this->test; } } $a = new A; // This should not raise notice foreach( $a->overloaded_property as $val ) echo $val."<br />\n"; // This should raise notice $a->overloaded_property[] = 6; ?> Thank you, Denis ------------------------------------------------------------------------ [2006-11-19 11:53:11] v dot anagnostos at mail dot bg Reproduce code: --------------- <?php class A{ private $test = array(1,2,3,4,5); public function __get($v){ return $this->test; } } $a = new A; foreach( $a->overloaded_property as $val ) echo $val."<br />\n"; ?> Expected result: ---------------- 1 2 3 4 5 Actual result: -------------- Notice: Indirect modification of overloaded property A::$overloaded_property has no effect in C:\Apache\htdocs\dancho\index.php on line 15 1 2 3 4 5 ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/39449 -- Edit this bug report at http://bugs.php.net/?id=39449&edit=1