-
-
Notifications
You must be signed in to change notification settings - Fork 394
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
Model::create()
issue with generics
#1149
Comments
Hi, I tried to replicate this. And I think this can be an issue with PHPStan. I'll try to prepare an example and open an issue there. Thanks. |
Thank you! |
Getting the same issue with /**
* @template T of Model
* @param class-string<T> $modelClassName
* @return T|null
*/
function findModel(string $modelClassName, int $id): ?Model
{
return $modelClassName::find($id);
} Gives the PHPStan error:
@canvural Did you ever make that issue in PHPStan? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
--level
used: 5Description
Not sure whether this is an issue with Larastan, Laravels type definitions or even PhpStan itself:
When running the
Model::create()
function on a class-string with a template definition, that's causing an issue. Seems like PhpStan cannot figure out the correct type.Laravel code where the issue was found
Simplified setup for the models:
Actual code which throws error
But this works:
The text was updated successfully, but these errors were encountered: