-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Fix for #18843 #18861
Conversation
ping @symfony/deciders |
@@ -156,12 +156,22 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp | |||
*/ | |||
private static function dumpArray($value, $exceptionOnInvalidType, $objectSupport) | |||
{ | |||
if ($value) { |
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 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;
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.
My solution uses less memory and is faster
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.
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.
Benchmark: |
👍 |
@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 |
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.
The method should be marked as @internal
.
@xabbuh done. |
Thank you @inso. |
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
Uh oh!
There was an error while loading. Please reload this page.