Bug #54143 [Nab]: array_merge returns NULL if a parameter is NULL
| From: | aharvey@php.net | Date: | Mon, 16 Jun 2014 20:13:46 +0000 |
| Subject: | Bug #54143 [Nab]: array_merge returns NULL if a parameter is NULL | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186216@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54143&edit=1
ID: 54143
Updated by: aharvey@php.net
Reported by: mchotai at fulcrum dot ca
Summary: array_merge returns NULL if a parameter is NULL
Status: Not a bug
Type: Bug
Package: Arrays related
Operating System: Ubuntu 9.3
PHP Version: 5.3SVN-2011-03-02 (SVN)
Block user comment: N
Private report: N
New Comment:
Internal functions return null if invalid parameters are provided. That's expected behaviour.
Previous Comments:
------------------------------------------------------------------------
[2014-06-16 18:57:04] 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.
------------------------------------------------------------------------
[2011-03-02 23:17:05] 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"
}
------------------------------------------------------------------------
[2011-03-02 22:44:19] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54143&edit=1