You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just noticed this with Container::onValidate – the property is expected to containarray<callable(static, T): void|callable(static, array): void|callable(T): void|callable(array): void> where T can be any object type but that is not expressible in PHPStan type language since containers like arrays are invariant in their item template types.
Would changing the stubs to just array<callable> and adding specific rules as a replacement be acceptable?
Activity
ondrejmirtes commentedon Nov 3, 2021
Given the types from the stub:
phpstan-nette/stubs/Forms/Form.stub
Lines 8 to 9 in f4654b2
this is expected behaviour by PHPStan. Because you're narrowing down the type of the second parameter from
mixedtoArrayHash.I understand that Nette contains some magic (https://github.com/nette/forms/blob/0f0c770db65ce2a18fc766b8b718b53e081ac8e2/src/Forms/Form.php#L424-L442) that will prevent this bug from happening. But PHPStan currently doesn't have the facilities to describe this behaviour, so feel free to just ignore the error: https://phpstan.org/user-guide/ignoring-errors
jtojnar commentedon Feb 24, 2023
I just noticed this with
Container::onValidate– the property is expected to containarray<callable(static, T): void|callable(static, array): void|callable(T): void|callable(array): void>whereTcan be anyobjecttype but that is not expressible in PHPStan type language since containers like arrays are invariant in their item template types.Would changing the stubs to just
array<callable>and adding specific rules as a replacement be acceptable?Comparison of the various type signatures: https://phpstan.org/r/a8969a90-ac6f-47f6-b11f-8df10e8f7e95
uestla commentedon Mar 3, 2023
@martenb I solved this with a custom
Formclass: