Doc #64909 [Opn]: array_merge - Return value documentation incorrect/misleading

From: Date: Fri, 24 May 2013 20:30:53 +0000
Subject: Doc #64909 [Opn]: array_merge - Return value documentation incorrect/misleading
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9882@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64909&edit=1 ID: 64909 User updated by: tim dot hentenaar at gmail dot com Reported by: tim dot hentenaar at gmail dot com Summary: array_merge - Return value documentation incorrect/misleading Status: Open Type: Documentation Problem Package: Documentation problem Operating System: N/A PHP Version: 5.4.15 Block user comment: N Private report: N New Comment: Hi Pete, Yes, that was my point exactly. In the example code, I didn't adhere to the signature of the function by passing a non-array argument. The method also doesn't adhere to its own signature by returning a non-array value. :P If one assumes, by the docs, that array_merge() will return the 'resulting array', then I would expect that even in case of error that array_merge() will still return something (empty or otherwise) of the 'array' type. It should probably be noted in the "Return values" section that NULL might possibly be returned in that particular case, since the implementation of array_merge() clearly does. Previous Comments: ------------------------------------------------------------------------ [2013-05-24 17:57:08] pete at petermcdonald dot co dot uk There is quite a large warning on the documentation advising that php5 MUST have arrays passed to it. It might be worth adding to the note advising of unexpected behaviour if array's are not passed but you have not adhered to the signature of the function therefore unexpected behaviour is for want of a better phrase, expected. ------------------------------------------------------------------------ [2013-05-23 14:04:28] tim dot hentenaar at gmail dot com Description: ------------ --- From manual page: http://www.php.net/function.array-merge#refsect1- function.array-merge-returnvalues --- "Return Values: Returns the resulting array." The documentation for the return values of array_merge() is not entirely correct. In fact, array_merge() will return NULL if one of its arguments is not an array, along with giving a warning. Either the documentation is wrong, and returning NULL is intended here, in which case the documentation needs to be updated; or array_merge() should be made to return an array (empty, or perhaps the initial array) in this case, since the documentation indicates that array_merge() returns an array. Test script: --------------- <?php # This shows that $r is actually assigned NULL. $r = array_merge(array('a' => 'b'),1); var_dump($r); ?> Expected result: ---------------- That the variable $r should be an array, with or without the warning. Actual result: -------------- Warning: array_merge(): Argument #2 is not an array in /home/tim/php/array_merge_test.php on line 4 NULL ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64909&edit=1

« previous php.doc.bugs (#9882) next »