-
Notifications
You must be signed in to change notification settings - Fork 160
[New Rule] Slow array SHOULD NOT be used in loop #20
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
Comments
What is going to happen with core code for which error is generated instead of warning by default? |
We can throw a warning with incremental approach. |
Mixed feelings. I often use merge in a reduce function to avoid changing local state (and save a line of code). |
Slow is a matter of definition :) In a loop with just a few iterations, you most likely won't notice that much of a difference. |
Exactly. That’s why focusing on big O algorithmic complexity seems like a good idea since that’s assumes scalability in the worst case scenario. |
For my point of view, This is good practice for developer who don't care about script execution it will also effect on performance and in the end it will slow down the site performance, This should be implemented.. |
Need you input here. See related PR #72 |
For me, it makes sense to have this rule |
Hi @kandy, |
@larsroettig, Definitely, there are some false positives and the warning is a good signal to review such places. |
#20 Impelement ArrayMerge sniff in foreach
Implemented in #72 |
…-coding-standard-221 [Imported] Version 7
Rule
The use of slow array functions (
array_merge
) in loop is discouraged.Reason
Merging arrays in a loop is slow and causes high CPU usage. Some benchmarking.
Bad example:
Good example:
Implementation
T_STRING
token and check if it's content isarray_merge
.The text was updated successfully, but these errors were encountered: