Skip to content

Abstract validator creates warning when an array value contains circular reference #40

Description

@michalbundyra

As the \Zend\Validator\AbstractValidator::createMessage method uses var_export to convert arrays to strings this fails if the array contains a circular reference. The problem line is https://github.com/zendframework/zend-validator/blob/master/src/AbstractValidator.php#L294.

I've provided a quick example of this below which outputs "PHP Warning: var_export does not handle circular references":

class ExampleValidator extends \Zend\Validator\AbstractValidator
{
    protected $messageTemplates = [
        'someError' => 'error'
    ];
    public function isValid($value)
    {
        $this->setValue($value);
        $this->error('someError');
        return false;
    }
}

class Circular {
    public $reference;
}

$test = new Circular();
$test->reference = $test;

$validator = new ExampleValidator();
$validator->isValid([$test]);

Originally posted by @tomp4l at zendframework/zend-validator#82

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions