-
-
Notifications
You must be signed in to change notification settings - Fork 863
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
@mixin does not support trait
s
#6778
Comments
@Paril After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
+PHP 8.2 (3 errors)
+==========
+
+13: PHPDoc tag @mixin contains invalid type Deprecations.
+20: Access to an undefined property MyClass::$caseSensitive.
+21: Access to an undefined property MyClass::$nonExistant.
+
+PHP 7.1 – 8.1 (2 errors)
+==========
+
13: PHPDoc tag @mixin contains invalid type Deprecations.
21: Access to an undefined property MyClass::$nonExistant. Full reportPHP 8.2 (3 errors)
PHP 7.1 – 8.1 (2 errors)
|
Similar behavior if you have an |
@Paril After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
+PHP 8.2 – 8.3 (3 errors)
+==========
+
+13: PHPDoc tag @mixin contains invalid type Deprecations.
+20: Access to an undefined property MyClass::$caseSensitive.
+21: Access to an undefined property MyClass::$nonExistant.
+
+PHP 7.1 – 8.1 (2 errors)
+==========
+
13: PHPDoc tag @mixin contains invalid type Deprecations.
21: Access to an undefined property MyClass::$nonExistant. Full reportPHP 8.2 – 8.3 (3 errors)
PHP 7.1 – 8.1 (2 errors)
|
@ondrejmirtes We’re hitting this issue with Craft CMS when we switch the PHP requirement to 8.2. Apparently several trait-defined properties have been flying under the PHPStan radar only because PHPStan thought they were dynamic properties, which they’re not. It would be great if PHPStan could be updated to respect trait-defined properties, including via interfaces, such as this one. |
@brandonkelly This is a hack that doesn't have a way to be represented in the filesystem. You're using an interface and you're expecting the implementations of the interface to be using a specific trait. There's no way to enforce that in PHP or PHPStan, and
I see a couple of ways out for you:
|
@ondrejmirtes Yeah, fully aware that we’re using interfaces wrong 🤦🏻 but we’re following Yii 2 conventions. We do plan on addressing that down the road, but that will be a widespread change on a large codebase with lots of downstream first/third party code that will need to adjust as well—so out of scope for now. Went ahead and posted a FR for |
Bug report
The
@mixin
phpdoc does not recognize traits as an acceptable input type. It does recognize the members of traits declared via@mixin
, but falsely reports that it is an invalid type.Code snippet that reproduces the problem
https://phpstan.org/r/d0921109-874b-47e4-83b3-aa98060912e9
Expected output
It should act similarly to Deprecations being a class or an interface. That seems to be how Intelephense and phpstorm interpret it.
The text was updated successfully, but these errors were encountered: