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
False-positive: Access to an uninitialized readonly property #10523
Comments
Yeah, the reproduction would be useful, ideally as a rule test case in phpstan-src. |
I managed to reproduce it in phpstan/phpstan-src#2897 - see https://github.com/phpstan/phpstan-src/actions/runs/7744684608/job/21118995083?pr=2897 could you have a look into a possible fix? I had a look already, but this stuff looks pretty complicated and its a new area for me atm |
I was touching this at some point last summer. This touches a similar issue phpstan/phpstan-src@218aad0 This was quite a substantial rewrite of the feature phpstan/phpstan-src@348debc |
after hours of investigation the only way I see this could be fixed - without regressing existing expected errors - would be to gather all property-fetches of that way we would know which properties will always exist and at the same time don't mix it up with inter-method-call assignments which can have various states - see e.g. https://github.com/phpstan/phpstan-src/blob/29a68b75ce9fa885886395df1acd23c06cff2a14/tests/PHPStan/Rules/Properties/data/missing-readonly-property-assign.php#L231-L246 to achieve this I would need to add these statements as a arg of wdyt? |
I feel like very similar situations in code are already well understood without false positives so this should be an easy fix. But I'd have to look into this myself to verify that. |
I think the current test-cases like e.g. work because the methods are called directly from the difference in my repro-case is, that the caller is a "additionalConstructor" and the scope of this additionalConstructor does not know about the scope of |
after a lunch walk I got an idea and implemented a fix in phpstan/phpstan-src#2897 |
@staabm After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.1 – 8.3 (2 errors)
+PHP 8.1 – 8.3 (5 errors)
==========
- 3: Class CheckoutController11 extends unknown class Zend_Controller_Action.
-14: Call to an undefined method CheckoutController11::redirectIfNkdeCheckoutNotAllowed().
+-1: Reflection error: Zend_Controller_Action not found.
+ 3: Reflection error: Zend_Controller_Action not found.
+ 3: Reflection error: Zend_Controller_Action not found.
+ 3: Reflection error: Zend_Controller_Action not found.
+ 3: Reflection error: Zend_Controller_Action not found.
PHP 7.2 – 8.0 (1 error)
==========
5: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 5 Full reportPHP 8.1 – 8.3 (5 errors)
PHP 7.2 – 8.0 (1 error)
|
Fixed phpstan/phpstan-src#2897 |
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
I have a class
and PHPStan configured with
additionalConstructors
:and I get the following errors:
I am wondering about the
27 Access to an uninitialized readonly property CheckoutController11::$userAccount.
error.I was not yet able to reproduce the problem in a small file outside of my project.
Code snippet that reproduces the problem
https://phpstan.org/r/dc8caf8e-bc01-4d08-9f65-172bb9235bb2
Expected output
no error on line 27, because of the initialization in
__construct
Did PHPStan help you today? Did it make you happy in any way?
No response
The text was updated successfully, but these errors were encountered: