Set/merge methods does not split key with dot
KarelWintersky opened this issue · comments
$dot->set('A', [
'E.X' => 5,
'E.Y' => 6,
'F' => 7
]);
var_dump( $dot->get() );
Return:
array(1) {
["A"]=>
array(3) {
["E.X"]=>
int(5)
["E.Y"]=>
int(6)
["F"]=>
int(7)
}
}
Expected:
array(1) {
["A"]=> array(2) {
["E"]=> array(2) {
["X"] => int(5)
["Y"] => int(6)
}
["F"] => int(7)
}
}
Hi @KarelWintersky 👋
Depending on your situation, you should use either set()
or add()
:
$dot->set([
'A.E.X' => 5,
'A.E.Y' => 6,
'A.F' => 7
]);
$dot->add([
'A.E.X' => 5,
'A.E.Y' => 6,
'A.F' => 7
]);
There are multiple ways to manipulate the content of the collection; please have a look at the documentation, and the test suite also has great examples.
It's not always possible declare collection as:
$dot->set([
'A.E.X' => 5,
'A.E.Y' => 6,
'A.F' => 7
]);
much more often the collection is declared "piece by piece":
$dot->add('A.F', 7);
// later
$dot->add('A', [ 'E.Y' => 6 ] );
// and so on..
It's not always possible declare collection as:
Yes, I totally get what you're saying, but over 150 libraries/apps depend on this package, and your suggestion would be a breaking change. I'll consider this in future major releases if more users would like to have this.
Appreciate your input 👍