note 48406 added to function.array-merge
| From: | ulderico at maber dot com dot br | Date: | Wed, 22 Dec 2004 14:30:28 +0000 |
| Subject: | note 48406 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-82179@lists.php.net to get a copy of this message | ||
OK! For those who are migrating from PHP 4 to PHP 5, there's a little thing to take care of...
When you array_merge in PHP 4, the compiler does not complain whether all arguments are typed as
Array. In PHP 5, the programmers wickedly enforced all arguments TO BE arrays... Thusly:
array_merge($var, $var2)
[as it is...]
will not work, in PHP5... It'll complain that Argument 1 and 2 ARE NOT arrays.
Well, one cannot always tell whether a second argument will be an Array. Even some times, however
more rarely, the first WILL NOT BE an array. Indeed, the PHP 4 behaviour was much more comfortable.
(Is it B&R?)
BUT YOU DO CAN cheat on PHP 5 and CAST the arguments as Arrays. Thusly:
array_merge((array) $var, (array) $var2)
[as it is...]
WILL work. It seems that the PHP engine developers had just put a little check on typing, but had
not changed very much in the logic of the tool.
This will work on both conditions mentioned above.
Dérico
----
Manual Page -- http://www.php.net/manual/en/function.array-merge.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48406
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48406&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48406&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48406&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48406&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48406&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48406&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48406&report=yes
Search -- http://master.php.net/manage/user-notes.php