php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40050 Array assignment without references
Submitted: 2007-01-07 19:57 UTC Modified: 2007-01-08 09:39 UTC
From: BenBE at omorphia dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.0 OS: Windows 2K
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: BenBE at omorphia dot de
New email:
PHP Version: OS:

 

 [2007-01-07 19:57 UTC] BenBE at omorphia dot de
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-07 21:58 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 [2007-01-07 22:52 UTC] BenBE at omorphia dot de
Please quote in detail the page of the manual you are referring to, as I can't find any reason why assigning an array with = should create such a weird pointer structure.

As mentioned below the =& assignment is right, only the = assignment is in question (and most likely wrong IMHO).
 [2007-01-08 09:39 UTC] bjori@php.net
Dupe of bug#38469
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 19:01:32 2025 UTC