Req #71658 [NEW]: Change array_merge() to merge valid parameters if any is invalid
| From: | wadev at mailbox dot hu | Date: | Wed, 24 Feb 2016 11:24:48 +0000 |
| Subject: | Req #71658 [NEW]: Change array_merge() to merge valid parameters if any is invalid | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-199447@lists.php.net to get a copy of this message | ||
From: wadev at mailbox dot hu
Operating system: Any
PHP version: 7.0.3
Package: Arrays related
Bug Type: Feature/Change Request
Bug description:Change array_merge() to merge valid parameters if any is invalid
Description:
------------
array_merge() function returns NULL if any of the arguments are not
arrays.
This makes for a lot of boilerplate code / guard clauses, such that I,
more often than not, rather end up using foreach for merging instead.
I don't know if I am the only one who expects it to either:
- return a merged array containing all of the valid arrays' keys/values,
or
- return a merged array containing all of the valid arrays' keys/values
before the first "invalid" argument.
This latter might (or might not) be preferrable on performance
considerations.
Please propose a change and/or vote on proposal if this is even
possible.
If so, I may make a patch if needed.
EDIT: as this seems similar to #64909, another proposal would be the
ability to change the emitted E_WARNING into a catchable fatal error.
This is quite strange that in such case we could catch a
java.lang.NullPointerException in Java, but nothing in PHP; quite
counter-productive.
Test script:
---------------
<?php
var_dump(array_merge(['what', 'ever'], false));
Expected result:
----------------
array(2) {
[0]=>
string(4) "what"
[1]=>
string(4) "ever"
}
Actual result:
--------------
<br />
<b>Warning</b>: array_merge(): Argument #2 is not an array in
<b>[...][...]</b> on line <b>2</b><br />
NULL
--
Edit bug report at https://bugs.php.net/bug.php?id=71658&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71658&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71658&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71658&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71658&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71658&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71658&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71658&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71658&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71658&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71658&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71658&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71658&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71658&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71658&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71658&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71658&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71658&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71658&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71658&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71658&r=mysqlcfg