Remove redundant warning in array_push() and array_unshift()#3011
Remove redundant warning in array_push() and array_unshift()#3011timurib wants to merge 1 commit intophp:masterfrom
Conversation
|
Comment on behalf of cmb at php.net: Thanks! Applied via f7f4864 (also added a note in UPGRADING and fixed the respective arginfos). |
Cf. <php/php-src#3011> git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@344569 c90b9560-bf6c-de11-be94-00142212c4b1
Cf. <php/php-src#3011> git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@344569 c90b9560-bf6c-de11-be94-00142212c4b1
Cf. <php/php-src#3011> git-svn-id: http://svn.php.net/repository/phpdoc/en@344569 c90b9560-bf6c-de11-be94-00142212c4b1
|
Very strange. Why did not you use other function instead of these? array_merge for example? |
|
@bolknote, yes, of course, Anyway, this commit don't change the actual behavior - the |
Of course I got it. :) But I still think that you can do it without this change. |
|
Speaking of |
Cf. <php/php-src#3011> git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@344569 c90b9560-bf6c-de11-be94-00142212c4b1
The
array_pushandarray_unshiftfunctions require at least 2 arguments. Requirement about second argument was relevant until version 5.6, because the codearray_push($array)really does not make sense. But with argument unpacking syntax we can use spread operator for array union:If the addition list length is not predefined then we should explicitly check the case when this list is emptiness to avoid the warning message, or prepend the expression with
@-operator. Actually the functions work well with single argument, they just do not change it. The warning is completely redundant and explicit checking negates the benefit (code size reducing) gained with the spread operator.For example, relevant array methods
pushandunshiftin the JavaScript work this way:Adding multiple elements to an array is a very common operation. This patch just will make it a little more convenient.
Unfortunately, it may cause the minor BC break for return value. Currently both functions returns
NULLwhen second argument is not passed. With this patch in this case they will return the length of array passed as first argument. Do I need to create RFC for such a small change?