|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-12-13 22:57 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 16:00:01 2025 UTC |
Description: ------------ I wanted to have array of objects. After assigning an object variable to a new array item (using bracket syntax $array[] = $object;), all items are identical. I found the bug in PHP 5.0.5/Linux and reproduced with 5.1.1/Windows. With 4.4.1 it works fine. Direct assignment ($array[]->property = ...;) works. Reproduce code: --------------- <?php // This overwrites items: $array = Array(); $object->property = 1; $array[] = $object; $object->property = 2; $array[] = $object; print_r($array); /* This works: * $array = Array(); * $array[]->property = 1; * $array[]->property = 2; * print_r($array); */ ?> Expected result: ---------------- After running this code I expect this output: Array ( [0] => stdClass Object ( [property] => 1 ) [1] => stdClass Object ( [property] => 2 ) ) Actual result: -------------- Array ( [0] => stdClass Object ( [property] => 2 ) [1] => stdClass Object ( [property] => 2 ) )