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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 12:01:31 2024 UTC