php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54143 array_merge returns NULL if a parameter is NULL
Submitted: 2011-03-02 22:44 UTC Modified: 2014-06-16 20:13 UTC
From: mchotai at fulcrum dot ca Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3SVN-2011-03-02 (SVN) OS: Ubuntu 9.3
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: mchotai at fulcrum dot ca
New email:
PHP Version: OS:

 

 [2011-03-02 22:44 UTC] mchotai at fulcrum dot ca
Description:
------------
$userdata = array_merge($user, $userdata);

If $user is NULL the result is NULL instead of $userdata.

Test script:
---------------
$userdata = array("Hi", "Jim");
$userdata = array_merge(NULL, $userdata);



Expected result:
----------------
Get back $userdata = array("Hi", "Jim")



Actual result:
--------------
NULL

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-02 23:17 UTC] dtajchreber@php.net
-Status: Open +Status: Bogus
 [2011-03-02 23:17 UTC] dtajchreber@php.net
It also gives you a warning explaining that parameter 1 isn't an array. If you 
want your output, cast NULL to an array:

var_dump(array_merge((array)NULL, array('a', 'b')));

array(2) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
}
 [2014-06-16 18:57 UTC] don at smugmug dot com
This is at least a bug in the documentation, where it states it'll always return an array:  http://us1.php.net/array_merge

But more likely is a problem in code, since it should probably always return an array like the docs suggest.  

Please fix one way or the other.
 [2014-06-16 20:13 UTC] aharvey@php.net
Internal functions return null if invalid parameters are provided. That's expected behaviour.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Apr 27 16:01:27 2025 UTC