I'm trying to use the Symfony Yaml dump function to output some nested php array data.
use \Symfony\Component\Yaml\Yaml;
echo Yaml::dump([
'arr'=>[],
'foo'=>'bar',
]);
However, the dumped YAML contains an empty object:
arr: { }
foo: bar
while I want an empty list:
arr: []
foo: bar
I tried using the Yaml::DUMP_OBJECT_AS_MAP flag, using the ArrayObject instead of array literals, and using an EmptyIterator, all to no avail.
I found two closed bugs related to this: https://github.com/symfony/symfony/issues/9870 and https://github.com/symfony/symfony/issues/15781, but the solutions there don't seem to work, or are a bit too hacky and brittle for my taste (str_replace on the YAML output, brrrr)
I have a simple testcase with what I tried so far: https://github.com/ComaVN/php-yaml-empty-array
Any suggestions on how to fix this?