php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43559 array_merge_recursive() doesn't behave as expected with duplicate NULL values
Submitted: 2007-12-11 05:35 UTC Modified: 2008-01-23 12:06 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: kraghuba at in dot ibm dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.2CVS-2007-12-11 (snap) OS: Linux, windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
26 - 11 = ?
Subscribe to this entry?

 
 [2007-12-11 05:35 UTC] kraghuba at in dot ibm dot com
Description:
------------
When two arrays having common key and value are passed as argument to array_merge_recursive(), the function behaves in an unexpected way for NULL values. It outputs an empty array instead of an array having two elements, both being NULL. Whereas, the function behaves in an expected way with values other than NULL. This behavior can be observed in the testcase array_merge_recursive_variation9.phpt.
   
This behavior is observed in PHP5.3 and PHP6 as well.

I tried creating an array with two null values and it works:
  <?php
  $a = array(NULL, NULL);
  var_dump($a);
  ?>
output:
  array(2) {
  [0]=>
  NULL
  [1]=>
  NULL
}




Reproduce code:
---------------
<?php
$a1 = array( 'b' => 'string' );
$a2 = array( 'b' => 'string' );
$a3 = array( 'b' => NULL );
$a4 = array( 'b' => NULL );
var_dump( array_merge_recursive($a1, $a2) );  // expected output
var_dump( array_merge_recursive($a3, $a4) );  // unexpecteed output
?>


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


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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-23 00:35 UTC] andrei@php.net
Looks fine to me.
 [2008-01-23 12:06 UTC] tony2001@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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 04:01:29 2024 UTC