Bug #65935
closedBug in ArrayUtility::mergeRecursiveWithOverrule
0%
Description
Hello together,
I found a bug in ArrayUtility::mergeRecursiveWithOverrule while merging two arrays. If you merge this:
array( 'key1' => array( 'key2' => 'x' ) )
with this:
array( 'key1' => 'y' )
I expect:
array( 'key1' => 'y' )
But I got:
array( 'key1' => array( 'key2' => 'x' ) )
This is because there is a nested "if" without an "else":
if (isset($original[$key]) && is_array($original[$key])) { if (is_array($overrule[$key])) { self::mergeRecursiveWithOverrule($original[$key], $overrule[$key], $addKeys, $includeEmptyValues, $enableUnsetFeature); } } elseif ...
this should be:
if (isset($original[$key]) && is_array($original[$key]) && is_array($overrule[$key])) { self::mergeRecursiveWithOverrule($original[$key], $overrule[$key], $addKeys, $includeEmptyValues, $enableUnsetFeature); } elseif ...
What do you think?
Updated by Markus Klein over 9 years ago
Well this is a very picky method. The current behaviour is covered well with unittests. May I ask for which purpose you need that method?
In 98% of all cases the native PHP methods work out and are much faster.
Updated by Markus Hölzle over 9 years ago
I use this function because of the "unset" feature. This makes it very simple to unset specific keys in an nested array. There I found this probably buggy code lines...
Updated by Markus Klein over 9 years ago
Oh dear, so you're one of the remaining 2% ;-)
I found a testcase for this:
typo3/sysext/core/Tests/Unit/Utility/ArrayUtilityTest.php:1530
'Override array does not reset array to string (weird!)' => array( array( 'first' => array(), ), array( 'first' => 'foo', ), TRUE, TRUE, TRUE, array( 'first' => array(), // This is rather unexpected, naive expectation: first => 'foo' ), ),
So this is indeed intended! (don't ask me why)
Updated by Mathias Schreiber over 9 years ago
- Sprint Focus set to On Location Sprint
Updated by Anja Leichsenring over 9 years ago
- Sprint Focus changed from On Location Sprint to Remote Sprint
Updated by Benni Mack about 7 years ago
- Status changed from New to Rejected
Sorry, Markus. We won't change this (instead, I've been trying to get rid of this ugly UNSET for a long time, as this is just too much PHP userland magic). As Markus K. mentioned, this is expected behaviour ;)