i'm trying use symfony yaml dump
function output nested php array data.
use \symfony\component\yaml\yaml; echo yaml::dump([ 'arr'=>[], 'foo'=>'bar', ]);
however, dumped yaml contains empty object:
arr: { } foo: bar
while want empty list:
arr: [] foo: bar
i tried using yaml::dump_object_as_map
flag, using arrayobject
instead of array literals, , using emptyiterator
, no avail.
i found 2 closed bugs related this: https://github.com/symfony/symfony/issues/9870 , https://github.com/symfony/symfony/issues/15781, solutions there don't seem work, or bit hacky , brittle taste (str_replace on yaml output, brrrr)
i have simple testcase tried far: https://github.com/comavn/php-yaml-empty-array
any suggestions on how fix this?
as of symfony 3.3 (released may 2017) can use new yaml::dump_empty_array_as_sequence
option:
yaml::dump($object, 2, 4, yaml::dump_empty_array_as_sequence);
this feature added in pr 21471.
Comments
Post a Comment