-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Remove redundant warning in array_push() and array_unshift() #3011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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_push
andarray_unshift
functions 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
push
andunshift
in 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
NULL
when 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?