Description
Right now YAML component dumps an empty array like this: $dump = array('test' => array());
as test: { }
. In some applications that use the YAML it needs to be test: [ ]
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.