Symfony Component Expression Language - Cannot Check Empty String

I tried to reproduce the language of expression in validation, and I found something strange.

Consider the Dog model

class Dog
{

    /**
     * @Assert\Expression("this.getName() != 'aa' ", message="Not good!")
     */
    private $name = 'aa';
    ...
}

'aa'! = 'aa' => false, so the verification service message is cool, but try to do the same with

class Dog
{

    /**
     * @Assert\Expression("this.getName() != '' ", message="Not good!")
     */
    private $name = '';
    ...
}

Does this return no error during validation? What for?

+4
source share
1 answer

Oh, I found a line that might interest you :)

line 47, provider /symfony/symfony/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php

if (null === $value || '' === $value) {
  return;
}
+1
source

Source: https://habr.com/ru/post/1534932/


All Articles