Skip to content
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

Fix array_merge with numeric keys #1218

Merged

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Apr 16, 2022

Found by luck. I'm surprised nobody noticed yet since 2018 :O
Currently numeric keys are simply overwritten / set directly without renumbering.

https://www.php.net/manual/en/function.array-merge.php

Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.

If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.

Values in the input arrays with numeric keys will be renumbered with incrementing keys starting from zero in the result array.

https://3v4l.org/fYp4K

@ondrejmirtes
Copy link
Member

Wow, thanks 😊

@ondrejmirtes ondrejmirtes merged commit 8084ab3 into phpstan:1.5.x Apr 16, 2022
@herndlm herndlm deleted the array-merge-with-constant-arrays branch April 19, 2022 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants