yiisoft / validator

Yii validator library
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
110 stars 36 forks source link

Doubled Nested with Callback produce error #719

Closed tomaszkane closed 3 weeks ago

tomaszkane commented 3 weeks ago

What steps will reproduce the problem?

Validate like this:

$data = [
    'items' => [
        ['variantId' => 123, 'quantity' => 1],
    ]
];

$rules = [
    'items' => [
        new Each([
            new Callback(callback: function(array $item) {
                $result = new Result();
                return $result;
            }),
        ]),
        new Each([
            new Callback(callback: function(array $item) {
                $result = new Result();
                return $result;
            }),
        ]),
    ]
];

$v = Container::get(ValidatorInterface::class);
$result = $v->validate($data, $rules);

What is the expected result?

$result has no error, no exceptions. Can use Each() many times.

What do you get instead?

TypeError
SomeClass::backend\controllers\{closure}(): Argument #1 ($item) must be of type array, int given, called in /var/www/project/vendor/yiisoft/validator/src/Rule/CallbackHandler.php on line 35

Thrown by second Callback(). $item was changes to int(123) - why?.

Additional info

Q A
Version 1.4.0
PHP version 8.0.x
Operating system Linux