<p dir="auto">I have a YML file that I parse, which has the following syntax for an empty array:</p>
<p dir="auto"><code class="notranslate">some_field: [ ]</code></p>
<p dir="auto">Upon dumping the same YML file, and not adjusting <code class="notranslate">some_field</code>, the value is dumped as:</p>
<p dir="auto"><code class="notranslate">some_field: { }</code></p>
<p dir="auto">My understanding is that the <code class="notranslate">{ }</code> syntax is intended for objects, not arrays. As such, I isolated the code found in the <code class="notranslate">dumpArray</code> function which was introducing this behavior:</p>
<p dir="auto"><a href="https://github.com/symfony/yaml/blob/2.8/Inline.php#L191">https://github.com/symfony/yaml/blob/2.8/Inline.php#L191</a></p>
<p dir="auto"><code class="notranslate">return sprintf('{ %s }', implode(', ', $output));</code></p>
<p dir="auto">.... adjusted to ....</p>
<p dir="auto"><code class="notranslate">return sprintf('[ %s ]', implode(', ', $output));</code></p>
<p dir="auto">... fixes this issue.</p>
<p dir="auto">Is there a reason why this is using the object-based syntax and not the array syntax?</p>
<p dir="auto">Right now YAML component dumps an empty array like this: <code class="notranslate">$dump = array('test' =&gt; array());</code> as <code class="notranslate">test: { }</code>. In some applications that use the YAML it needs to be <code class="notranslate">test: [ ]</code> a list instead of a hash.</p>
<p dir="auto">In the symfony codebase on this line (<a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Yaml/Inline.php#L160">https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Yaml/Inline.php#L160</a>) I found:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        $keys = array_keys($value);
        if ((1 == count($keys) &amp;&amp; '0' == $keys[0])
            || (count($keys) &gt; 1 &amp;&amp; array_reduce($keys, function ($v, $w) { return (integer) $v + $w; }, 0) == count($keys) * (count($keys) - 1) / 2)
        ) {"><pre class="notranslate"><code class="notranslate">        $keys = array_keys($value);
        if ((1 == count($keys) &amp;&amp; '0' == $keys[0])
            || (count($keys) &gt; 1 &amp;&amp; array_reduce($keys, function ($v, $w) { return (integer) $v + $w; }, 0) == count($keys) * (count($keys) - 1) / 2)
        ) {
</code></pre></div>
<p dir="auto">It looks to me if I pass <code class="notranslate">$dump = array('test' =&gt; array('0' =&gt; ''))</code> It should work? However this code outputs: <code class="notranslate">test: - ''</code>. Its successfully using the list format but its passing the blank value. I think another conditional is missing to be able to create: <code class="notranslate">test: [ ]</code>. I checked the unit tests and I can't find anywhere that explains what <code class="notranslate">(1 == count($keys) &amp;&amp; '0' == $keys[0])</code> was intended for other than this purpose.</p>
<p dir="auto">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 <code class="notranslate">[ ]</code> instead of hash <code class="notranslate">{ }</code> since it is invalid yaml for what I am using it for and a blank array defaults to the hash.</p>