-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Consider replacing array_replace() with array union (+ operator) #7029
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
I also think we should promote array unions as a best practice. On top of that the code would be faster which is an other small benefit. |
I'll make a PR for this soon, question is: on which branch should this go? 2.0, 2.1, 2.2, or master? I'd prefer 2.2 since it would benefit the upcoming release and it's not a breaking change/new feature. @vicb any pointers? |
What about php 5.3 ? |
I'm against this change for many reasons:
|
@lyrixx what about it? It behaves the same in PHP 5.3+ (until 5.5 alpha4) If @fabpot doesn't agree with this then I'll hold of with the PR. Also, if you ever need to compare different functions speed/memory usage/opcodes/ outputs against multiple PHP versions you can use this site: http://3v4l.org/ |
@fabpot, your last statement is debatable. My original concern was not even about speed but readability, I always have to check the documentation to ensure how array_replace works, instead of +. |
@dlsniper Ok. I just asked if php 5.3 has the same (speed) behavior than php 5.4. |
@rybakit but when you see @lyrixx what could cause a speed difference is xDebug which slows down functions (this is the reason for most of the difference between |
@stof I don't see what else than "union" a + between two array would mean ? And this is the first intend of the PR, makes thing clearer (vs If you read the history (link on top) you will see that xDebug is disabled and speed optimization is not the primary goal but just something that comes with. |
@stof, actually
Even if you know how array_replace works, you can't guarantee that $c is array, it can be null according to the documentation. It's more like |
usually $b is an "array()" definition, an $a is a parameter (options) But I must admit that improving readability is subjective here (Fabien & you find "+" harder to read than array_replace). So maybe the best thing to do is to close this issue ? |
See discussion of #6995 (comment)
The text was updated successfully, but these errors were encountered: