php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46649 Setting array element with that same array produces inconsistent results
Submitted: 2008-11-22 23:08 UTC Modified: 2008-11-23 20:39 UTC
From: binarysurgeon at gmail dot com Assigned:
Status: Closed Package: *General Issues
PHP Version: 5.2.6 OS: Linux 2.6
Private report: No CVE-ID:
 [2008-11-22 23:08 UTC] binarysurgeon at gmail dot com
Description:
------------
When setting an a particular array element to the array itself, results are different when it's inside a function vs outside the function.

Reproduce code:
---------------
function func()
{
    $a[1] = '1';
    $a[0] = $a;
    var_dump($a);
}

func();

$a[1] = '1';
$a[0] = $a;
var_dump($a);

Expected result:
----------------
I'm not sure what to expect but at the vary least, the results should be consistent.  Results were consistent in 5.2.1.

array(2) {
  [1]=>
  string(1) "1"
  [0]=>
  array(1) {
    [1]=>
    string(1) "1"
  }
}
array(2) {
  [1]=>
  string(1) "1"
  [0]=>
  array(1) {
    [1]=>
    string(1) "1"
  }
}


Actual result:
--------------
array(2) {
  [1]=>
  string(1) "1"
  [0]=>
  NULL
}
array(2) {
  [1]=>
  string(1) "1"
  [0]=>
  array(1) {
    [1]=>
    string(1) "1"
  }
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-23 20:39 UTC] lbarnaud@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 21:01:56 2014 UTC