diff --git a/validation/custom_constraint.rst b/validation/custom_constraint.rst index 4e947290ef0..b946901c6f8 100644 --- a/validation/custom_constraint.rst +++ b/validation/custom_constraint.rst @@ -65,6 +65,10 @@ The validator class is also simple, and only has one required method ``validate( { public function validate($value, Constraint $constraint) { + if (!$constraint instanceof ContainsAlphanumeric) { + throw new UnexpectedTypeException($constraint, ContainsAlphanumeric::class); + } + // custom constraints should ignore null and empty values to allow // other constraints (NotBlank, NotNull, etc.) take care of that if (null === $value || '' === $value) {