Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions lib/Cake/Utility/Hash.php
Expand Up @@ -756,18 +756,15 @@ public static function dimensions(array $data) {
* number of dimensions in a mixed array.
*
* @param array $data Array to count dimensions on
* @param int $count counts current depth of this iteration
* @return int The maximum number of dimensions in $data
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html#Hash::maxDimensions
*/
public static function maxDimensions(array $data) {
$depth = array();
public static function maxDimensions($data, $count = 0) {
$depth = array($count);
if (is_array($data) && reset($data) !== false) {
foreach ($data as $value) {
if (is_array($value)) {
$depth[] = self::dimensions($value) + 1;
} else {
$depth[] = 1;
}
$depth[] = static::maxDimensions($value, $count + 1 );
Copy link
Member

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+?

Copy link
Member

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

}
}
return empty($depth) ? 0 : max($depth);
Expand Down