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

Fix Hash::maxDimensions #7040

wants to merge 2 commits into from

Conversation

jadedcore
Copy link
Contributor

** 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:

$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.

** 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.
@dereuromark
Copy link
Member

Can you also add a test case for this please?

@dereuromark dereuromark added this to the 2.7.1 milestone Jul 16, 2015
Fixed whitespace issue caught by Travis CI
@jadedcore
Copy link
Contributor Author

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 );
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

@antograssiot
Copy link
Contributor

@jadedcore you could add your example here so it will prevent future regression

@markstory markstory self-assigned this Jul 16, 2015
markstory pushed a commit that referenced this pull request Jul 21, 2015
Added test case for Hash::maxDimensions using the example array in pull request #7040.
markstory added a commit that referenced this pull request Jul 21, 2015
We don't need the additional parameter, and some of the tests weren't
covering unique scenarios.

Refs #7040
markstory added a commit that referenced this pull request Jul 21, 2015
Merges pull requests #7041 and #7040 into 2.7
@markstory
Copy link
Member

Merged into 2.7 in 27e40f0

@markstory markstory closed this Jul 21, 2015
markstory added a commit that referenced this pull request Jul 21, 2015
@markstory
Copy link
Member

Ported to 3.x in 742f85d

markstory added a commit that referenced this pull request Jul 24, 2015
Replacing self with static due to PHP5.3+. Following #7040.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants