php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17654 array_merge() throws warning when supplied with 1 argument only
Submitted: 2002-06-08 08:16 UTC Modified: 2002-06-29 11:37 UTC
From: carlos at wfmh dot org dot pl Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.2.1 OS: Linux GNU/Debian
Private report: No CVE-ID: None
 [2002-06-08 08:16 UTC] carlos at wfmh dot org dot pl
array_merge() throws an "Wrong parameter count" if called with only 1 argument given. I consider it a bug, as there's no technical reason it should act that way. One can say merging one array makes no sense, which is correct from logical point of view, but from the ther side, technical, there's nothing that I can imagine to prevent array_merge()  to handle this case w/o any error. Currently if I write a code that utilises array_merge() and I plan it to scale later on, I can 't simply write

$res = array_merge( $arr1 );

and expand the lists later on, if I get more arrays.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-08 08:34 UTC] sander@php.net
Don't know if we want to change this. I don't quite see the use of it.
Anyway, if you want to change it yourself look at line 1934 of /ext/standard/array.c and change the 2 to 1 (in the function php_array_merge_wrapper).
 [2002-06-08 09:19 UTC] carlos at wfmh dot org dot pl
A few pro's for changing this permanently:

1. Is syntax $a = $a throwing any warning? Again, you may say it makes no sense, but technically it's valid and it work, because there's no real reason it should either throw any warning or refuse to work.
2. There's nothing that makes a array_merge($arr) call invalid, as produced result is 100% valid as in $a=$a.
3. It does not influence PHP syntax nor causes bad programming habbits.
4. Finally, 'fixing' this does not broke backward compatibility, neither is a security issue ;)

I'd bet we could raise the contest and people could give enough dirty examples of helpful use of potentially nonsense syntax during the development process.

PS: The same applies to array_merge_recursive() I presume.
 [2002-06-29 11:37 UTC] derick@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC