<p dir="auto">Symfony 2.6.5 version changed the way errors are displayed in the browser. Lately a lot of users are complaining about this new behavior: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="68105416" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/14337" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/14337/hovercard" href="https://github.com/symfony/symfony/issues/14337">#14337</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="66146195" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/14199" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/14199/hovercard" href="https://github.com/symfony/symfony/issues/14199">#14199</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1096546" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/1396" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony/pull/1396/hovercard" href="https://github.com/symfony/symfony/pull/1396">#1396</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="65204451" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/14111" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/14111/hovercard" href="https://github.com/symfony/symfony/issues/14111">#14111</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="64586466" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/14073" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/14073/hovercard" href="https://github.com/symfony/symfony/issues/14073">#14073</a>.</p>
<p dir="auto">Symfony 2.7 beta tried to solve this problem, but the result is not completely satisfactory.</p>
<p dir="auto">To better understand the problem, check out the different error messages that you get when your controller uses the <code class="notranslate">@Security</code> annotation without importing its associated class.</p>
<h3 dir="auto">Symfony 2.6.4</h3>
<p dir="auto">The error message is perfect.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/73419/7124728/a9ecdc2a-e22b-11e4-8626-9a0d10456c5b.png"><img src="https://cloud.githubusercontent.com/assets/73419/7124728/a9ecdc2a-e22b-11e4-8626-9a0d10456c5b.png" alt="2_6_4_web" style="max-width: 100%;"></a></p>
<h3 dir="auto">Symfony 2.6.5 and 2.6.6</h3>
<p dir="auto">The error message is awful.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/73419/7124730/bab1730e-e22b-11e4-96eb-8915b5c14d43.png"><img src="https://cloud.githubusercontent.com/assets/73419/7124730/bab1730e-e22b-11e4-96eb-8915b5c14d43.png" alt="2_6_6_web" style="max-width: 100%;"></a></p>
<h3 dir="auto">Symfony 2.7</h3>
<p dir="auto">You see 4 error messages instead of just 1. The good error is displayed at the bottom and the awful error is displayed first.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/73419/7124736/c5213234-e22b-11e4-81c1-21f4b390833d.png"><img src="https://cloud.githubusercontent.com/assets/73419/7124736/c5213234-e22b-11e4-81c1-21f4b390833d.png" alt="2_7_dev_web" style="max-width: 100%;"></a></p>
<p dir="auto">This behavior only happens in the browser. If you use Symfony 2.6.5 or 2.6.6 in the console, you get perfect error messages:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/73419/7124764/f5529218-e22b-11e4-87bd-defe2dacab34.png"><img src="https://cloud.githubusercontent.com/assets/73419/7124764/f5529218-e22b-11e4-87bd-defe2dacab34.png" alt="2_6_4_cli" style="max-width: 100%;"></a></p>
<p dir="auto">In my opinion this is a <strong>critical issue</strong> that should be fixed both for 2.6 and 2.7.</p>
<p dir="auto">I've recently encountered a strange issue with validation groups:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="class Profile {
    /**
     * @Assert\NotBlank(message=&quot;NOT-BLANK-Default&quot;)
     * @Assert\NotBlank(message=&quot;NOT-BLANK-Profile&quot;, groups={ &quot;Profile&quot; })
     */
    public $firstName;
}

$profile = new Profile();
$errors = $validator-&gt;validate($profile, array('Profile'))

foreach($errors as $e) {
    echo (string) $e;
}"><pre class="notranslate"><code class="notranslate">class Profile {
    /**
     * @Assert\NotBlank(message="NOT-BLANK-Default")
     * @Assert\NotBlank(message="NOT-BLANK-Profile", groups={ "Profile" })
     */
    public $firstName;
}

$profile = new Profile();
$errors = $validator-&gt;validate($profile, array('Profile'))

foreach($errors as $e) {
    echo (string) $e;
}
</code></pre></div>
<p dir="auto">Expected result would be:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Profile.firstName:
    NOT-BLANK-Profile"><pre class="notranslate"><code class="notranslate">Profile.firstName:
    NOT-BLANK-Profile
</code></pre></div>
<p dir="auto">However the actual result is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Profile.firstName:
    NOT-BLANK-Default
Profile.firstName:
    NOT-BLANK-Profile"><pre class="notranslate"><code class="notranslate">Profile.firstName:
    NOT-BLANK-Default
Profile.firstName:
    NOT-BLANK-Profile
</code></pre></div>
<p dir="auto">On the other hand, if we explictly define validation groups as <code class="notranslate">array('Default', 'Profile')</code> the result is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Profile.firstName:
    NOT-BLANK-Default
Profile.firstName:
    NOT-BLANK-Default
Profile.firstName:
    NOT-BLANK-Profile"><pre class="notranslate"><code class="notranslate">Profile.firstName:
    NOT-BLANK-Default
Profile.firstName:
    NOT-BLANK-Default
Profile.firstName:
    NOT-BLANK-Profile
</code></pre></div>
<p dir="auto">It happens because <code class="notranslate">Symfony\Component\Validator\Mapping\ClassMetadata</code> impliclty adds <code class="notranslate">Default</code> validation group when it encounters a validation group that has the same as validated class name (w/o namespace). This behaviour is not documented, it causes hard to debug errors (including: duplicated error messages) and what's worst it changes validation logic.</p>