-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Yaml] properly parse lists in object maps #17729
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
Conversation
xabbuh
commented
Feb 8, 2016
Q | A |
---|---|
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #17709, #17710, #17711 |
License | MIT |
Doc PR |
- do not cast parsed sequences to objects
- properly handle numeric mapping keys
👍 |
@@ -303,8 +303,14 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport = | |||
mb_internal_encoding($mbEncoding); | |||
} | |||
|
|||
if ($objectForMap && !is_object($data)) { | |||
$data = (object) $data; |
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 don't understand why we made this change:
- $data = (object) $data;
+ $object = new \stdClass();
+
+ foreach ($data as $key => $value) {
+ $object->$key = $value;
+ }
+
+ $data = $object;
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.
PHP behaves a bit different when it comes to numeric keys (see https://3v4l.org/dUGiM).
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.
@xabbuh thanks for the explanation!
c907339
to
81a164e
Compare
* do not cast parsed sequences to objects * properly handle numeric mapping keys
81a164e
to
ee9ca93
Compare
👍 Status: reviewed |
Thank you @xabbuh. |
This PR was merged into the 2.8 branch. Discussion ---------- [Yaml] properly parse lists in object maps | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17709, #17710, #17711 | License | MIT | Doc PR | * do not cast parsed sequences to objects * properly handle numeric mapping keys Commits ------- ee9ca93 [Yaml] properly parse lists in object maps