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
Null coalescing operator throwing access property error #3171
Null coalescing operator throwing access property error #3171
Comments
Here's one using array shapes: |
@shmax PHPStan now reports different result with your code snippet: @@ @@
-13: Offset 'filters' does not exist on array(?'filters' => array(?'keywords' => string)).
+No errors |
@Krunch PHPStan now reports different result with your code snippet: @@ @@
+PHP 8.0 (1 error)
+==========
+
+15: Cannot access property $someArray on PropertyClass|null.
+
+PHP 7.3 – 7.4 (2 errors)
+==========
+
+ 5: Property PropertyClass::$someArray has no typehint specified.
+11: Property HelloWorld::$property has no typehint specified.
+
+PHP 7.1 – 7.2 (1 error)
+==========
+
15: Cannot access property $someArray on PropertyClass|null. Full reportPHP 8.0 (1 error)
PHP 7.3 – 7.4 (2 errors)
PHP 7.1 – 7.2 (1 error)
|
@Krunch After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
+11: Property HelloWorld::$property is never written, only read.
15: Cannot access property $someArray on PropertyClass|null. Full report
|
@Krunch After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
+11: Property HelloWorld::$property is never written, only read.
15: Cannot access property $someArray on PropertyClass|null. Full report
|
@Krunch After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-15: Cannot access property $someArray on PropertyClass|null.
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md Full report
|
@Krunch After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-15: Cannot access property $someArray on PropertyClass|null.
+15: Cannot access property $someArray on PropertyClass|null.
+11: Property HelloWorld::$property is never written, only read. Full report
|
Should be fixed by specifying types in isset. Related issue phpstan/phpstan#3171
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. |
Bug report
Code snippet that reproduces the problem
https://phpstan.org/r/c03dea3a-c5d2-4fa7-85e5-2e58f5f43cd1
Error message:
Cannot access property $someArray on PropertyClass|null.
Expected output
No phpstan error. Null coalesce already properly handles nested nulls, and array access to missing keys properly. There is no ambiguity in the code, no dynamic properties are being used so this should be properly handled by phpstan.
Interesting note: If you remove
|null
from the@var
notation then no phpstan error is thrown. It seems to be only triggered when$property
can also benull
.Also, if
$someArray
happened to be something other than an array (likestring|null
) it would also properly work and phpstan would throw no error.The text was updated successfully, but these errors were encountered: