Phalcon\Config->merge() sometimes deletes the last key/value of first config
Expected and Actual Behavior
I am trying to merge two configs. This works nice when all keys in the config are strings, but produces unexpected results when all keys are integers or numeric strings. Simplest example to reproduce I could come up with:
use Phalcon\Config;
$config = new Config([1 => 'Apple']);
$config2 = new Config([2 => 'Banana']);
$config->merge($config2);
print_r($config);
Expected behaviour:
Phalcon\Config Object
(
[1] => Apple
[2] => Banana
)
Actual behaviour:
Phalcon\Config Object
(
[1] => Banana
)
Several examples:
// Same code as above but array starting at 0; this merges as expected
$config = new Config([0 => 'Apple']);
$config2 = new Config([1 => 'Banana']);
// Any *non-numeric* string as key in the arrays being merged; this merges as expected
$config = new Config([1 => 'Apple', 'p' => 'Pineapple']);
$config2 = new Config([2 => 'Banana']);
// To illustrate nested configs: "One" will merge as expected, "Two" will not
$config = new Config([
'One' => [1 => 'Apple', 'p' => 'Pineapple'],
'Two' => [1 => 'Apple'],
]);
$config2 = new Config([
'One' => [2 => 'Banana'],
'Two' => [2 => 'Banana'],
]);
Details
I've reproduced this behaviour on 3 different servers:
PHP 7.1.12, Phalcon 3.2.0, Zephir 0.9.8-6335775f25 PHP 7.1.8, Phalcon 3.2.1, Zephir 0.9.9-868cb1f92b PHP 7.2.3, Phalcon 3.3.2, Zephir 0.10.7-2917ebe8ae
- Operating System: Ubuntu 7.2.0 and CentOS 7.4
- Installation type: Compiling from source
- Server: Apache
Hi,
I think this is related with this code: https://github.com/phalcon/cphalcon/blob/4b37bdfaf277b4493532e5ead1dfc9449fe3ed17/phalcon/config.zep#L325-L329 That works fine with some numeric keys and does not with others.
Regards, Federico.
This has been resolved