Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Template Covariance and Extending Classes #9836

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

I'm struggling to understand why this is causing a type error. It is loosely based on Laravel's Models/Collections.

https://phpstan.org/r/02e1dd3b-fa0d-4c00-8e8f-6c6718912e94

I was able to find a similar issue here but it doesn't quite solve the issuing I'm having:

#9735

Should the theCollection function return MyCollection<int, Model> like phpstan is suggesting? I figured any class that inherits from the Model class would be acceptable.

You must be logged in to vote

There's an open bug for this: #2735

To work around the problem, you need to repeat the constructor in child classes: https://phpstan.org/r/190c32ad-e8c7-4809-8b1c-c1a9981fc3e5

Replies: 1 comment

Comment options

There's an open bug for this: #2735

To work around the problem, you need to repeat the constructor in child classes: https://phpstan.org/r/190c32ad-e8c7-4809-8b1c-c1a9981fc3e5

You must be logged in to vote
0 replies
Answer selected by TomKita
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /