Replies: 2 comments 1 reply
-
/**
* @template T0 of OtherInterface
*/
interface FirstInterface {
}
/**
* @template T1 of FirstInterface
*/
interface OtherInterface {
} My mind does not compute :) This should be forbidden TBH. You can't write a useful typehint with this design. What are you trying to achieve? |
Beta Was this translation helpful? Give feedback.
-
Hello, I don't know if this has been fixed or if it was only due to errors in the given example, but it works like this with latest versions of PHP : https://phpstan.org/r/ffd38f35-f703-4489-91f9-1bc9c538bc72 . For former versions, just replace the signature of I understand that this seems peculiar at first, but it actually makes sense in some cases, we use it in our code, and it is handled correctly by PHPStan most of the time, if it is able to resolve templates to concrete types (since it can then infer all template types from the concrete ones). |
Beta Was this translation helpful? Give feedback.
-
Hello, I'm trying to resolve a
Function test1() has parameter $first with generic interface FirstInterface but does not specify its types: T0
error without success.I have the impression that when there is a dependency loop between two interfaces it is not possible to specify the generic type.
I don't think this is a bug because it seems legitimate for PHPStan to ask for more precision.
So my question : is there a best practice or trick for dealing with this kind of case ?
Here is a reproductible playground.
It happens to me in practice for Doctrine entities that are linked in a relationship.
Beta Was this translation helpful? Give feedback.
All reactions