#36571 [Csd]: __set() affects outer variable when overloading with "[]=" and "{}="

From: Date: Mon, 07 Aug 2006 10:46:48 +0000
Subject: #36571 [Csd]: __set() affects outer variable when overloading with "[]=" and "{}="
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-100453@lists.php.net to get a copy of this message
ID: 36571 User updated by: cid73 at 163 dot com Reported By: cid73 at 163 dot com Status: Closed Bug Type: Scripting Engine problem Operating System: * PHP Version: 5.1.3RC3 Assigned To: dmitry New Comment: All right, now I know how to do, thanks a lot! BTW, would you consider always pass arrays by reference like many other languages do? Previous Comments: ------------------------------------------------------------------------ [2006-08-07 08:42:01] tony2001@php.net $object->a = value; and $object->b[] = value; are completely different things. For the second line to work __get() must return by reference, but __get() always returns *by value*. So this is the expected and correct result. ------------------------------------------------------------------------ [2006-08-07 08:10:40] cid73 at 163 dot com Excuse me, my purpose was obvioursly to create a setter class, and then after I do: ------------ $o = new Setter($a); $o->a[0] = 'A'; $o->a[] = 'd'; $o->b{0} = 'h'; print_r($o); // note: it's $o, not $a --------------- I think the result should now be: Setter Object ( [attributes:private] => Array ( [a] => Array ( [0] => A [1] => b [2] => c [3] => d ) [b] => hello ) ) The old problem was "$a was modified", this problem has been fixed; but the problem now goes to $o: all the assignments don't work. Let's see what I get: Setter Object ( [attributes:private] => Array ( [a] => Array ( [0] => a [1] => b [2] => c ) [b] => Hello ) ) I tested it with 5.2-dev ------------------------------------------------------------------------ [2006-08-06 16:04:18] tony2001@php.net Yes, I did test it with 5.2-dev. Array ( [a] => Array ( [0] => a [1] => b [2] => c ) [b] => Hello ) ------------------------------------------------------------------------ [2006-08-06 15:54:17] cid73 at 163 dot com Are you sure it is fixed now? Did you test $o->a and $o->b, or print_r($o)? :-) ------------------------------------------------------------------------ [2006-08-01 22:49:53] tony2001@php.net Not reproducible with 5.2-CVS. ------------------------------------------------------------------------ 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/36571 -- Edit this bug report at http://bugs.php.net/?id=36571&edit=1

« previous php.bugs (#100453) next »