<p dir="auto">There are several cases where one property is only required depending on some other properties. It's not possible to use the expression validator in such cases.</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    public function validate($value, Constraint $constraint)
    {
        if (null === $value || '' === $value) {
            return;
        }
        // ....
    }"><pre class="notranslate">    <span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">validate</span>(<span class="pl-s1"><span class="pl-c1">$</span>value</span>, <span class="pl-smi"><span class="pl-smi">Constraint</span></span> <span class="pl-s1"><span class="pl-c1">$</span>constraint</span>)
    {
        <span class="pl-k">if</span> (<span class="pl-c1">null</span> === <span class="pl-s1"><span class="pl-c1">$</span>value</span> || <span class="pl-s">''</span> === <span class="pl-s1"><span class="pl-c1">$</span>value</span>) {
            <span class="pl-k">return</span>;
        }
        <span class="pl-c">// ....</span>
    }</pre></div>
<p dir="auto">Example: I have a state property which is only required if my country property has states.</p>
<div class="highlight highlight-text-xml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="        &lt;property name=&quot;state&quot;&gt;
            &lt;constraint name=&quot;Expression&quot;&gt;
                &lt;option name=&quot;expression&quot;&gt;
                    !this.getCountry().hasStates() or null !== value
                &lt;/option&gt;
                &lt;option name=&quot;message&quot;&gt;
                    Please select a state
                &lt;/option&gt;                
            &lt;/constraint&gt;            
        &lt;/property&gt; "><pre class="notranslate">        &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>state<span class="pl-pds">"</span></span>&gt;
            &lt;<span class="pl-ent">constraint</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>Expression<span class="pl-pds">"</span></span>&gt;
                &lt;<span class="pl-ent">option</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>expression<span class="pl-pds">"</span></span>&gt;
                    !this.getCountry().hasStates() or null !== value
                &lt;/<span class="pl-ent">option</span>&gt;
                &lt;<span class="pl-ent">option</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>message<span class="pl-pds">"</span></span>&gt;
                    Please select a state
                &lt;/<span class="pl-ent">option</span>&gt;                
            &lt;/<span class="pl-ent">constraint</span>&gt;            
        &lt;/<span class="pl-ent">property</span>&gt; </pre></div>
<p dir="auto">If the state is null, it should raise an error but this will never happen due to the first condition of the validate method.</p>
<p dir="auto">Empty properties are not validated by default:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="class ExpressionValidator extends ConstraintValidator
            public function validate($value, Constraint $constraint)

                        if (null === $value || '' === $value) {
                                    return;
                        }"><pre class="notranslate"><code class="notranslate">class ExpressionValidator extends ConstraintValidator
            public function validate($value, Constraint $constraint)

                        if (null === $value || '' === $value) {
                                    return;
                        }
</code></pre></div>
<p dir="auto">it has sense for serveral validators (Issn, Data, etc), but in case of  Expression validator it makes it impossible to use for following case "if other value is provided then this one cannot be empty".<br>
Dummy example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="class Dog
{
    /**
     * @Assert\NotBlank()
     */
    private $age;

    /**
     * @Assert\Expression(&quot;this.getAge() &gt; 10 ? true : this.getName() != '' &quot;, message=&quot;Dog name is required when dog is older then 10 years&quot;)
     */
    private $name;
"><pre class="notranslate"><code class="notranslate">class Dog
{
    /**
     * @Assert\NotBlank()
     */
    private $age;

    /**
     * @Assert\Expression("this.getAge() &gt; 10 ? true : this.getName() != '' ", message="Dog name is required when dog is older then 10 years")
     */
    private $name;

</code></pre></div>
<p dir="auto">So is it bug or feature ;) ?</p>