Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[YAML] Blank Array without Hash #9870

Closed
Labels
@patrickheeney

Description

@patrickheeney

Right now YAML component dumps an empty array like this:$dump = array('test' => array()); astest: { }. In some applications that use the YAML it needs to betest: [ ] a list instead of a hash.

In the symfony codebase on this line (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Yaml/Inline.php#L160) I found:

        $keys = array_keys($value);        if ((1 == count($keys) && '0' == $keys[0])            || (count($keys) > 1 && array_reduce($keys, function ($v, $w) { return (integer) $v + $w; }, 0) == count($keys) * (count($keys) - 1) / 2)        ) {

It looks to me if I pass$dump = array('test' => array('0' => '')) It should work? However this code outputs:test: - ''. Its successfully using the list format but its passing the blank value. I think another conditional is missing to be able to create:test: [ ]. I checked the unit tests and I can't find anywhere that explains what(1 == count($keys) && '0' == $keys[0]) was intended for other than this purpose.

EDIT: It doesn't look to be hitting that section of code at all since my indent level is really high. However I am still tring to figure out how to get it to output a[ ] instead of hash{ } since it is invalid yaml for what I am using it for and a blank array defaults to the hash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp