When I call something like:
$class_name = 'AppModelsUser';
$class_name::create($attributes);
PhpStorm shows an inspection warning "Method ‘create’ not found in string".
I don’t want to switch off this inspection, as it’s very useful in other cases. Is there another way to avoid the warning, using annotations or something else?
2
Answers
I've found another way, maybe someone will use it:
Not ideal, but works fine
The warning you’re seeing in PhpStorm is likely due to the fact that PhpStorm is statically analyzing the code, and when you use a string to represent a class name, PhpStorm can’t infer the actual class and, therefore, doesn’t recognize the methods associated with that class.
To mitigate this, you can use PHPDoc annotations: