|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-04-07 11:46 UTC] mo at nevali dot net
Description: ------------ Some circumstances involving deep references into arrays can cause assignment of those arrays to always assign references instead of values. Reproduce code: --------------- Please see http://nevali.net/docs/array-refs-testcase.phps Expected result: ---------------- The code should produce the following output: Created foo, foo->thing['stuff'] = 1234 Creating Bar, foo->thing['stuff'] = 1234 Created bar, bar->thing2['stuff'] = ABC Created bar, foo->thing['stuff'] = 1234 Actual result: -------------- Created foo, foo->thing['stuff'] = 1234 Creating Bar, foo->thing['stuff'] = 1234 Created bar, bar->thing2['stuff'] = ABC Created bar, foo->thing['stuff'] = ABC If the (marked) line in Foo's constructor: $this->stuff =& $this->thing['stuff']; ?is removed, the output is as expected, even though this code should be inert (Foo::stuff is not referenced from anywhere else in the test code). PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 22:00:01 2025 UTC |
colder@jack /var/cvs/php.net/php5.3-dev $ sapi/cli/php -r '$v = 2; $a = array("k" => &$v); $b = $a; $b["k"]++; echo $v;' 3 When arrays get copied, the elements that are references are kept as references.