8000 Fix for #18843 by inso · Pull Request #18861 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix for #18843 #18861

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

Closed
wants to merge 7 commits into from
Closed

Fix for #18843 #18861

wants to merge 7 commits into from

Conversation

inso
Copy link
@inso inso commented May 24, 2016
Q A
Branch? 2.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #18843
License MIT
Doc PR -

@inso
Copy link
Author
inso commented May 26, 2016

ping @symfony/deciders

@@ -156,12 +156,22 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
*/
private static function dumpArray($value, $exceptionOnInvalidType, $objectSupport)
{
if ($value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was intrigued by this problem: "how to detect if an array is associative or not" and I found two one-liners on StackOverflow. Maybe we can simplify this code?

$isMapping = array_keys($value) !== range(0, count($value) - 1);

$isMapping = count(array_filter(array_keys($value), 'is_string')) > 0;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My solution uses less memory and is faster

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Dumper class we use array_keys($input) !== range(0, count($input) - 1) to detect the type of array. I am fine with changing the way we detect it, but then we should move the detection into a dedicated method an reuse it in both places.

@inso
Copy link
Author
inso commented May 26, 2016

@nicolas-grekas
Copy link
Member

👍

@xabbuh xabbuh added the Yaml label May 29, 2016
@inso
Copy link
Author
inso commented May 29, 2016

@xabbuh comments addressed, but I'm not sure where isHash method should be placed.

*
* @param array $value The PHP array to check
*
* @return bool true if value is hash array, false otherwise
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method should be marked as @internal.

@inso
Copy link
Author
inso commented May 29, 2016

@xabbuh done.

@nicolas-grekas
Copy link
Member

Thank you @inso.

nicolas-grekas added a commit that referenced this pull request May 30, 2016
This PR was squashed before being merged into the 2.3 branch (closes #18861).

Discussion
----------

Fix for #18843

| Q             | A
| ------------- | ---
| Branch?       | 2.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18843
| License       | MIT
| Doc PR        | -

Commits
-------

7d78196 Fix for #18843
@fabpot fabpot mentioned this pull request May 30, 2016
This was referenced Jun 6, 2016
@fabpot fabpot mentioned this pull request Jun 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0