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
Fix Hash::maxDimensions #7040
Fix Hash::maxDimensions #7040
Conversation
** Closed the 2.8 pull request and opened this one instead. ** The current Hash::maxDimensions function calls Hash::dimensions to try to get the maximum depth of the passed in array. However, this ends up only getting the depth of the first element of each 1st dimension element in the array passed to maxDimensions. The function needs to be called recursively in order to get the depth of ALL of the elements in all of the dimensions of the passed in array. I made the maxDimensions function more closely resemble the deprecated Set::countDim function in order to restore the correct functionality. Example: $data = array( 0 => array( 0 => 'Some Value', 1 => array( 0 => 'Some other Value' ) ), 1 => array( 0 => 'Some Value', ) ); Returns 2 under the current version of maxDimensions. Returns 3 with the changes proposed above.
Can you also add a test case for this please? |
Fixed whitespace issue caught by Travis CI
Hi @dereuromark, I am not sure what you mean by add a test case. I added an example array in the opening comment that counts incorrectly using the original method and correctly with this modification. Is there something else you would like me to do? |
} else { | ||
$depth[] = 1; | ||
} | ||
$depth[] = static::maxDimensions($value, $count + 1 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we OK with the self => static change for 2.7+?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am. composer.json
says PHP>=5.3.0
@jadedcore you could add your example here so it will prevent future regression |
Added test case for Hash::maxDimensions using the example array in pull request #7040.
We don't need the additional parameter, and some of the tests weren't covering unique scenarios. Refs #7040
Merged into 2.7 in 27e40f0 |
Ported to 3.x in 742f85d |
Replacing self with static due to PHP5.3+. Following #7040.
** Closed the 2.8 pull request and opened this one instead. Issue #7022 **
The current Hash::maxDimensions function calls Hash::dimensions to try to get the maximum depth of the passed in array. However, this ends up only getting the depth of the first element of each 1st dimension element in the array passed to maxDimensions. The function needs to be called recursively in order to get the depth of ALL of the elements in all of the dimensions of the passed in array.
I made the maxDimensions function more closely resemble the deprecated Set::countDim function in order to restore the correct functionality.
Example:
Returns 2 under the current version of maxDimensions.
Returns 3 with the changes proposed above.