#39449 [Asn->Csd]: Overloaded array properties do not work correctly
| From: | dmitry@php.net | Date: | Wed, 10 Jan 2007 16:01:10 +0000 |
| Subject: | #39449 [Asn->Csd]: Overloaded array properties do not work correctly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-107429@lists.php.net to get a copy of this message | ||
ID: 39449
Updated by: dmitry@php.net
Reported By: pstradomski at gmail dot com
-Status: Assigned
+Status: Closed
Bug Type: Scripting Engine problem
Operating System: Linux
PHP Version: 5.2.0
Assigned To: dmitry
New Comment:
Fixed in CVS HEAD and PHP_5_2.
Previous Comments:
------------------------------------------------------------------------
[2007-01-06 10:19:01] slavikus at gmail dot com
I do agree with the brjann points and also vote for this
behavior to be fixed; there's no way for me to knowing if any
particular property is overloaded or not, neither it is right
to treat them differently from any other properties.
------------------------------------------------------------------------
[2006-12-22 12:20:30] tim dot pickup at gmail dot com
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 ?
------------------------------------------------------------------------
[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
------------------------------------------------------------------------
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