<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>yes</td>
</tr>
<tr>
<td>Feature request?</td>
<td>no</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>3.2.9</td>
</tr>
</tbody>
</table>
<p dir="auto">Hello,</p>
<p dir="auto">I'm not sure this is really a bug but the console running is surprising.</p>
<p dir="auto">The context is, i propose to my users to select one value from array to backup database. So, I've one array like this : [ '2017-08-08-17-15-06-name', '2017-08-07-17-15-01-name', '2017-08-08-17-15-10-name', '2017-08-08-17-15-14-name']</p>
<p dir="auto">When I use "choice" function from SymfonyStyle class (<a href="http://symfony.com/blog/new-in-symfony-2-8-console-style-guide" rel="nofollow">http://symfony.com/blog/new-in-symfony-2-8-console-style-guide</a>) (<a href="http://api.symfony.com/3.3/Symfony/Component/Console/Style/SymfonyStyle.html#method_choice" rel="nofollow">http://api.symfony.com/3.3/Symfony/Component/Console/Style/SymfonyStyle.html#method_choice</a>), I get this output :</p>
<p dir="auto"><code class="notranslate">[0] 2017-08-08-17-15-06-name [1] 2017-08-07-17-15-01-name [2] 2017-08-06-17-15-10-name [3] 2017-08-05-17-15-14-name</code></p>
<p dir="auto">That OK.</p>
<p dir="auto">If my user press '1', the selected value is 2017-08-07-17-15-01-name =&gt; Good.</p>
<p dir="auto">But, if my user press '2', the selected value is 2017-08-08-17-15-06-name</p>
<p dir="auto">I've seen the array_flip (line 238 from SymfonyStyle class) but i'm not sure this is the problem.</p>
<p dir="auto">Of course in my case, this is a big problem.</p>
<p dir="auto">I've tried to reproduce this in virgin context. With  :</p>
<blockquote>
<p dir="auto">$values = array ('1112', '15412', '6541244', '15888', '225451', '355425');<br>
$choiceqQuestion = new ChoiceQuestion("Quel script voulez-vous exécuter ou dans quel répertoire souhaitez-vous vous rendre ?", $values);<br>
$chx = $io-&gt;askQuestion($choiceqQuestion);<br>
var_dump($chx)</p>
</blockquote>
<p dir="auto">The result is :</p>
<blockquote>
<p dir="auto">Quel script voulez-vous exécuter ou dans quel répertoire souhaitez-vous vous rendre ?:<br>
[0] 1112<br>
[1] 15412<br>
[2] 6541244<br>
[3] 15888<br>
[4] 225451<br>
[5] 355425</p>
</blockquote>
<blockquote>
<p dir="auto">2<br>
225451</p>
</blockquote>
<blockquote>
<p dir="auto">string(6) "225451"</p>
</blockquote>
<p dir="auto">This running makes me think of this function autocomplete the input to select output.</p>
<p dir="auto">Thanks</p>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>yes</td>
</tr>
<tr>
<td>Feature request?</td>
<td>no</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>yes</td>
</tr>
<tr>
<td>Symfony version</td>
<td>3.2.4</td>
</tr>
</tbody>
</table>
<p dir="auto">My situation is as follows:<br>
I have a console application that uses a ChoiceQuestion with version numbers as values. Rendered the question looks like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  [0]: 3.0.0
  [1]: 2.2.0
  [2]: 2.1.3"><pre class="notranslate"><code class="notranslate">  [0]: 3.0.0
  [1]: 2.2.0
  [2]: 2.1.3
</code></pre></div>
<p dir="auto">If I select option "2" I'll get "2.2.0", because the value gets autocompleted.</p>
<p dir="auto">It even fails with associative arrays:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  [a]: berlin
  [b]: copenhagen
  [c]: amsterdam"><pre class="notranslate"><code class="notranslate">  [a]: berlin
  [b]: copenhagen
  [c]: amsterdam
</code></pre></div>
<p dir="auto">If I select "b", I get "a", the key of the first option, as its value is found by the autocompleter.</p>
<p dir="auto">Here is a testcase to demonstrate the behaviour:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
    public function testAmbiguousKeyFromChoicelist()
    {
        $possibleChoices = array(
            'a' =&gt; 'berlin',
            'b' =&gt; 'copenhagen',
            'c' =&gt; 'amsterdam',
        );

        $dialog = new QuestionHelper();
        $helperSet = new HelperSet(array(new FormatterHelper()));
        $dialog-&gt;setHelperSet($helperSet);

        $question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
        $question-&gt;setMaxAttempts(1);

        $answer = $dialog-&gt;ask($this-&gt;createStreamableInputInterfaceMock($this-&gt;getInputStream(&quot;b\n&quot;)), $this-&gt;createOutputInterface(), $question);

        $this-&gt;assertSame(&quot;b&quot;, $answer);
    }"><pre class="notranslate">    <span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">testAmbiguousKeyFromChoicelist</span>()
    {
        <span class="pl-s1"><span class="pl-c1">$</span>possibleChoices</span> = <span class="pl-en">array</span>(
            <span class="pl-s">'a'</span> =&gt; <span class="pl-s">'berlin'</span>,
            <span class="pl-s">'b'</span> =&gt; <span class="pl-s">'copenhagen'</span>,
            <span class="pl-s">'c'</span> =&gt; <span class="pl-s">'amsterdam'</span>,
        );

        <span class="pl-s1"><span class="pl-c1">$</span>dialog</span> = <span class="pl-k">new</span> <span class="pl-v">QuestionHelper</span>();
        <span class="pl-s1"><span class="pl-c1">$</span>helperSet</span> = <span class="pl-k">new</span> <span class="pl-v">HelperSet</span>(<span class="pl-en">array</span>(<span class="pl-k">new</span> <span class="pl-v">FormatterHelper</span>()));
        <span class="pl-s1"><span class="pl-c1">$</span>dialog</span>-&gt;<span class="pl-en">setHelperSet</span>(<span class="pl-s1"><span class="pl-c1">$</span>helperSet</span>);

        <span class="pl-s1"><span class="pl-c1">$</span>question</span> = <span class="pl-k">new</span> <span class="pl-v">ChoiceQuestion</span>(<span class="pl-s">'Please select the environment to load'</span>, <span class="pl-s1"><span class="pl-c1">$</span>possibleChoices</span>);
        <span class="pl-s1"><span class="pl-c1">$</span>question</span>-&gt;<span class="pl-en">setMaxAttempts</span>(<span class="pl-c1">1</span>);

        <span class="pl-s1"><span class="pl-c1">$</span>answer</span> = <span class="pl-s1"><span class="pl-c1">$</span>dialog</span>-&gt;<span class="pl-en">ask</span>(<span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">createStreamableInputInterfaceMock</span>(<span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">getInputStream</span>("<span class="pl-s">b</span>\n")), <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">createOutputInterface</span>(), <span class="pl-s1"><span class="pl-c1">$</span>question</span>);

        <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">assertSame</span>("<span class="pl-s">b</span>", <span class="pl-s1"><span class="pl-c1">$</span>answer</span>);
    }</pre></div>
<p dir="auto">A possible solutions could be:</p>
<ul dir="auto">
<li>Do not consider keys as autocomplete values (so keys must match exactly)</li>
<li>Do consider keys as autocomplete values, but the take precedence over values</li>
</ul>
<p dir="auto">My preference would be the first option.</p>