|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-01-07 21:58 UTC] iliaa@php.net
[2007-01-07 22:52 UTC] BenBE at omorphia dot de
[2007-01-08 09:39 UTC] bjori@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 00:00:01 2025 UTC |
Description: ------------ When assigning an array by-value into itself PHP will insert a self-referencing Array into the new entry Reproduce code: --------------- $a = array(); $a[] =& $a; print_r($a); $b = array(); $b[] = $b; print_r($b); Expected result: ---------------- array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } array(1) { [0]=> array(0) { } } $b[0] should contain an empty array because $b was assigned by-value, i.e. should get copied. Actual result: -------------- array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } Comparing the references (see my entry regarding Spotting References) you find that $b and $b[0] are different pointers and $b[0] is an array like the one created in $a.