Skip to content

Dataset is not passed to context in StopOnError() #822

Description

@jettero777

Description

Current scope's dataset is not set in context inside StopOnError():

'property' => [
    new Callback(
        function (mixed $value, Callback $rule, ValidationContext $context): Result {
            $context->getDataSet()->getData(); // <= dataset array
        }
    ),
    new StopOnError([
        new Callback(
            function (mixed $value, Callback $rule, ValidationContext $context): Result {
                $context->getDataSet()->getData(); // <= null (bug)
            }
        ),
    ]),
]

this could be worked around using $context->getGlobalDataSet() and extracting data from there,
but it would be not possible in case if multiple nested Each() used, because in context parameters there is index for the last Each() only

Package version

No response

PHP version

No response

Activity

  1. jettero777 commented on Sep 25, 2026

    @jettero777
    Author

    I traced why it is null, current data set inside StopOnError() is being set to property's value, and in that case 'property' had null value.

    Obviously it is not desired behavior, context's dataset should not be changed upon entering into StopOnError().
    Rules inside StopOnError() should work the same way as without it (except stopping on an error of course).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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