-
-
Notifications
You must be signed in to change notification settings - Fork 864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with generics and extends #4008
Comments
parent::__construct doesn't currently work correctly from generics point of view. There's definitely an issue about that already, but I'm gonna keep this one open too. |
ok perfect, thanks :) i don't know how complicated the fix would be, but i would definitely be interested to try to help on this |
not sure if related, but the following code does not work in playground:
there is probably some infinity recursion, which makes even the |
shouldn't you do this way? <?php
declare(strict_types = 1);
/**
* @template T
*/
abstract class A
{
}
/**
* @template T
* @extends A<T>
*/
class B extends A
{
} |
@nikophil I already did it that way, but that code is very dangerous as it can be very easily missed to be renamed when copying to another child class - thus |
@nikophil After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-20: Parameter #1 $otherGenericClass of method GenericClass<BaseModel>::__construct() expects OtherGenericClass<BaseModel>, OtherGenericClass<Model> given.
+No errors |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Support question
Hello,
i'm trying to solve a "contravariance problem" with generics.
I reproduced my problem in phpstan's playground: https://phpstan.org/r/74032d14-212e-4d02-9871-dc2e80ec2808
I don't understand why in the context of my object
ChildGenericClass
contextualized onModel
, i cannot pass to its parent's constructor a generics contextualized onModel
as well.thanks for your help and amazing work :)
The text was updated successfully, but these errors were encountered: