note 103693 deleted from function.array-merge by danbrown
| From: | danbrown@php.net | Date: | Thu, 28 Apr 2011 15:08:42 +0000 |
| Subject: | note 103693 deleted from function.array-merge by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179231@lists.php.net to get a copy of this message | ||
Note Submitter: Lev
----
jerry at gii dot co dot jp was spot on when he brought up the fact that NULL will be returned in
newer PHP builds if any of the arguments are empty.
This caused me a bit of headache to figure out at first because I was expecting to be able to just
surpress any warnings with:
$merged = @array_merge($a, $b);
... as I was expecting in some situations one of the arrays to be null (dynamically parsing XML
here...).
To make a long story short; it does seem a bit silly that this is the case. In my opinion, it would
make more sense to throw the warning and continue on, instead of completely failing.
To prevent this - if you expect one of your arguments could ever be null, just do:
$merged = array_merge((array)$a, (array)$b);
This will safeguard against any situations in which one array might not be set and will always get
an array returned.