This story begins as a conversation on phpc.social with Ben Ramsey. At first, I thought I found a bug in PHP core while working on a Laravel application. At first, I turned to report the issue on http://github.com/php/php-src. But, little did I know PHP
array_merge was working as expected… reindexing numeric keys! This was an issue I found in Laravel, not PHP.
I submitted a PR to Laravel that addressed the issue by swapping
array_replace. And Taylor was very kind to merge and commit the PR.
I love it when I run into issues that stump me, like this one, because I learn the nuances of PHP, and the solutions tend to stick with me for a long time. Now I will not forget
array_replace have significant differences and will be more intentional moving forward – do not jump straight for
array_merge to join arrays.
To bring the story to a close:
- Push through hard problems to learn deeply. I could have shrugged and taken a different route. I’m glad I did not.
- Reach out for help. Your insights are not robust until you ask others to help you.
- Do leave the solution in the dark. Take the time to contribute what you find and clear the road for others. In this case, it was a PR.