Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
michalbundyra opened this issue Jan 15, 2020 · 2 comments

Comments

@michalbundyra
Copy link
Member

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

@michalbundyra
Copy link
Member Author

Can you avoid the circular dependency?

To be honest I don't think we will implement some kind of circular depedency check because it could affect to the performance.


Originally posted by @Maks3w at zendframework/zend-validator#82 (comment)

@michalbundyra
Copy link
Member Author

I've worked around it by handling the array to string conversion manually by overriding setValue. This may cause issues with built in validators provided by Zend but it's only a minor inconvenience for my use case.


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant