-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[YAML] Question about array dumping #16266
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
Comments
See #16267 for a fix. The problem was that the method filtered the array keys on whether it has only numeric keys (in which case a Yaml sequence should be dumped) or some string keys as well (in which case a Yaml mapping ( |
@wouterj, I am currently using 2.8. Will your patch also be applied to that version? |
This looks like a duplicate of #9870 to me. |
see #17728 |
This PR was merged into the 3.1-dev branch. Discussion ---------- [Yaml] add option to dump objects as maps | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9870, #12860, #15781, #15937, #16266 | License | MIT | Doc PR | TODO Commits ------- 3941d2e [Yaml] add option to dump objects as maps
…0657) This PR was squashed before being merged into the 3.3-dev branch (closes #21471). Discussion ---------- [Yaml] Allow dumping empty array as YAML sequence | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9870, #15937, #16266 | License | MIT | Doc PR | PHP arrays are dumped as either YAML sequences or mappings, depending on whether the array has continuos integer keys or not. An empty array is always dumped as a YAML mapping. Sometimes you want it dumped as a YAML sequence instead. Commits ------- 87ffaf2 Bump version number af7067c Dump empty object as mapping a6d94c1 [Yaml] Allow dumping empty array as YAML sequence
I have a YML file that I parse, which has the following syntax for an empty array:
some_field: [ ]
Upon dumping the same YML file, and not adjusting
some_field
, the value is dumped as:some_field: { }
My understanding is that the
{ }
syntax is intended for objects, not arrays. As such, I isolated the code found in thedumpArray
function which was introducing this behavior:https://github.com/symfony/yaml/blob/2.8/Inline.php#L191
return sprintf('{ %s }', implode(', ', $output));
.... adjusted to ....
return sprintf('[ %s ]', implode(', ', $output));
... fixes this issue.
Is there a reason why this is using the object-based syntax and not the array syntax?
The text was updated successfully, but these errors were encountered: