-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
array_push(...) calls behaving as '$array[] = ...', $array[] = works faster than invoking functions in PHP #16144
array_push(...) calls behaving as '$array[] = ...', $array[] = works faster than invoking functions in PHP #16144
Conversation
…faster than invoking functions in PHP
Hi @lfluvisotto. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
@lfluvisotto nice, didn't know that 👍 Really x10 performance boost? O.o Don't think it is a measurable imrpvement but like the Please add |
Hi @orlangur I didn't get you meant What am I supposed to do? |
@lfluvisotto you are supposed to make https://github.com/magento/magento2/blob/2.2-develop/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php#L202 catch such occurrences. Here is the sniff I'm referring to: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/PHP/ForbiddenFunctionsSniff.php |
@lfluvisotto you can find example where function was added to forbidden list: |
@ihor-sviziev I believe this is incorrect usage of obsolete methods and they are not even running on Travis :/ |
@orlangur @ihor-sviziev I believe |
So do we add array_push to the list of forbidden functions or not? Like the PHP note says: http://php.net/manual/en/function.array-push.php I prefer don't use array_push. |
@ishakhsuvarov why? It's more wordy and slower anyway :) Let's proceed with this PR and I'll propose corresponding sniff as separate PR, then we can discuss. |
Hi @orlangur, thank you for the review. |
@orlangur do I create other PR to put the array_push function to the list of forbidden functions? |
@lfluvisotto not needed, thanks, I have a couple of other phpcs-related staff in my ToDo, will contribute it this month. |
…ay[] = works faster than invoking functions in PHP #16144
Hi @lfluvisotto. Thank you for your contribution. Please, consider to port this solution to 2.3 release line. |
@lfluvisotto this is just a bot, better mention or even directly assign reviewers of original PR 😉 |
Description
array_push(...) calls behaving as '$array[] = ...', $array[] = works faster than invoking functions in PHP
See note in PHP documentation:
http://php.net/manual/en/function.array-push.php
Note: If you use array_push() to add one element to the array, it's better to use $array[] = because in that way there is no overhead of calling a function.