4

I tried to play around Expression Language in validation, and I found something strange.

Let's consider Dog model

class Dog
{

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

'aa' != 'aa' => false so validation service reports error - cool, but lets try to do the same with

class Dog
{

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

This one does not return any error during validation??? Why?

1 Answer 1

2

Oh, I've found line that you can be interested by :)

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

if (null === $value || '' === $value) {
  return;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.