Skip to content

Conversation

@dereuromark
Copy link
Member

Summary

The return type array<string, array<string, string>> didn't account for nested validators. When using addNested() or addNestedMany(), the error values can be nested arrays, not just strings.

Example with nested validator:

$validator->addNested('address', $addressValidator);

Error structure when nested validation fails:

[
    'address' => [
        'street' => ['_required' => 'This field is required'],
        'city' => ['_required' => 'This field is required'],
    ]
]

The inner values are array<string, string>, not string.

Fix: Updated return type to array<string, array<string, string|array>> which accurately reflects the actual return structure when nested validators are used.

The return type `array<string, array<string, string>>` was too restrictive
and didn't account for nested validators. When using `addNested()` or
`addNestedMany()`, the error values can be nested arrays, not just strings.

Updated the return type to `array<string, array<string, string|array>>`
which accurately reflects the actual return structure.

Fixes #19112
@dereuromark dereuromark added this to the 5.2.11 milestone Dec 14, 2025
@dereuromark dereuromark marked this pull request as ready for review December 14, 2025 09:28
@ADmad ADmad merged commit 3ffb0d1 into 5.x Dec 14, 2025
15 checks passed
@ADmad ADmad deleted the fix-validator-return-type branch December 14, 2025 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Too narrow type hint for validate()

3 participants