Req #73576 [NEW]: Create array_concat alias for array_merge

From: Date: Mon, 21 Nov 2016 22:01:31 +0000
Subject: Req #73576 [NEW]: Create array_concat alias for array_merge
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205535@lists.php.net to get a copy of this message
From: ian at ianchanning dot com Operating system: N/A PHP version: 5.6.28 Package: Arrays related Bug Type: Feature/Change Request Bug description:Create array_concat alias for array_merge Description: ------------ There is no documented array concatenation function. This is a very common function, e.g. Javascript and Ruby have the concat function, Python has + and Haskell has ++. The array_merge function (http://php.net/manual/en/function.array-merge.php) is what has be used if you want to concatenate arrays. However it is not mentioned in the documentation (not even in the comments) of that method that that is what should be used. I propose that array_concat be created as an alias of array_merge. The concatenation of an associative array is also consistent with trying to merge the hash maps. For example this Stack Overflow question on [concatenating two dictionaries](http://stackoverflow.com/questions/1781571/how-to-concatenate-two-dictionaries-to-create-a-new-one-in-python#1784128) is marked as a duplicate of the function 'How to merge two Python dictionaries'. That is, it is consistent that hash map concatenation is the same as hash map merging. So I believe that array_concat is a perfect alias for array_merge in terms of numeric arrays and a valid (albeit unnecessary) alias for associative arrays. This will help almost all developers coming to PHP from other dynamic languages. Test script: --------------- <?php var_dump(array_concat(array('London'), array('Calling'))); ?> Expected result: ---------------- array(2) { [0]=> string(6) "London" [1]=> string(7) "Calling" } -- Edit bug report at https://bugs.php.net/bug.php?id=73576&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73576&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73576&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73576&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=73576&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=73576&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=73576&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=73576&r=needscript Try newer version: https://bugs.php.net/fix.php?id=73576&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=73576&r=support Expected behavior: https://bugs.php.net/fix.php?id=73576&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=73576&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=73576&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=73576&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73576&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=73576&r=dst IIS Stability: https://bugs.php.net/fix.php?id=73576&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=73576&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=73576&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=73576&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=73576&r=mysqlcfg

« previous php.bugs (#205535) next »