Skip to content

Question about generics and required verbosity #10798

Closed Answered by ondrejmirtes
petervossen asked this question in Support
Discussion options

You must be logged in to vote

The tip on the playground tries to explain it:

Type A is not always the same as TA. It breaks the contract for some argument types, typically subtypes.

What it means: Let's say you have C<X, Y>. This means that getAWithError has to return X.

If you have C<Alpha, Beta>, getAWithError needs to return Alpha.

Your types do not guarantee that. This is the fix: https://phpstan.org/r/72a9e0a7-4c7d-4ed7-9977-64b1df59ca05

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@petervossen
Comment options

Answer selected by petervossen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants