-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[BUG]: Phalcon\Config::merge change in 4.x #14705
Comments
I think this issue needs some discussion. Personally I would like to align with how PHP is handeling this. http://sandbox.onlinephpfunctions.com/code/e79296edb95931346f14fb2155ae70965d586516
https://www.php.net/manual/en/function.array-merge.php |
I think current condition need to be here, to make sure that key is not overridden: Line 191 in b28b0a2
If in But, we need to update the docs with such examples as above. |
I agree with @Jeckerson - the closer we are to PHP's native methods the better it is. It makes it easier for developers to use it. I would venture to say even that |
But this is about config so numeric keys might need to remain as they are. For example in PDO, the constructor options are key value pairs like |
Hello, |
@gpkappos This behavior will be fixed in next release or some. |
Resolved in #15723 |
@niden I believe the numerical-index merging is still a problem. Consider this test case, running on $array1 = ['first'];
$array2 = ['second', 'third'];
print_r((new Phalcon\Config\Config())
->merge($array1)
->merge($array2)
->toArray()
); gives:
Even when I nested these arrays within a string-indexed child array, I got the same result for the merged element. Elements are always overwritten by their numerical indexes. Based on the comments above, I thought the intention was to make the result like
Did I just misunderstand the intended result from this fix, or is there still something to be adjusted here? |
Phalcon\Config::merge() now works, in some parts, for integer keys as PHP's array_merge. Integer keys do not get overwritten, but integer keys also do not get reindexed/renumbered.
The behavior is even stranger when we already have some numeric key inside, before merge, as keys get appended/incremented. Some examples below:
Script to reproduce:
Output (as expected) on Phalcon 3.x:
Everything is OK. empty has received 3 => toEmpty and nonEmpty has received 3 => toNonEmpty.
Output on Phalcon 4.x is completely different:
Here we see that empty receives key [0]. And nonEmpty gets appended to next key.
Expected behavior
I think Phalcon 3.x is the expected behavior, since this is configuration and keys may be important. Maybe add argument to Config::merge to overwrite or reindex keys on merge?
I didn't tested it, but simply removing elseif in https://github.com/phalcon/cphalcon/blob/master/phalcon/Config.zep#L191 would probably return to 3.x behavior.
If you'd like to move back to 3.x behavior I can try and change Config.zep and make PR.
Details
The text was updated successfully, but these errors were encountered: