Skip to content

AbstractComparisonValidator gives TypeError with type hinted getter #30133

Closed
@nick-zh

Description

@nick-zh

Symfony version(s) affected: symfony/valdiator 4.2.3

Description
I am using the constraint Symfony\Component\Validator\Constraints\GreaterThanOrEqual
My getters have typehinted return values. So if i validate a string (expected to be int) i get a type error.
This is happening because the Symfony\Component\Validator\Constraints\AbstractComparisonValidator uses the PropertyAccessor (which calls the getter) unlike e.g. the RecursiveContextualValidator
which uses

$propertyValue = $propertyMetadata->getPropertyValue($object);

I haven't found a good solution besides changing my code or implementing an own property accessor.
Maybe i have overlooked something, but i think this should still work without custom additions.

EDIT: The constructcor of the AbstractComparisonValidator now uses the concrete class in the constructor, i think this should at least be:

public function __construct(PropertyAccessorInterface $propertyAccessor = null)
{
    $this->propertyAccessor = $propertyAccessor;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions