Skip to content
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 property" #9619

Closed
lulco opened this issue Jul 12, 2023 · 9 comments
Closed

False positive "Access to an uninitialized property" #9619

lulco opened this issue Jul 12, 2023 · 9 comments

Comments

@lulco
Copy link

lulco commented Jul 12, 2023

Bug report

Since phpstan 1.10.23 there is an error reported if property marked as initialized is accessed in additional constructor method.
See phpstan/phpstan-nette#129

Code snippet that reproduces the problem

No response

Expected output

no error

Did PHPStan help you today? Did it make you happy in any way?

No response

@mergeable
Copy link

mergeable bot commented Jul 12, 2023

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@218aad0

@lulco
Copy link
Author

lulco commented Jul 12, 2023

Thanks for quick fix

@lulco
Copy link
Author

lulco commented Jul 20, 2023

@ondrejmirtes Hi, this is still an issue if property is set via __construct() and accessed in additional constructor:

(startup is marked as additional constructor)

class AdminPresenter extends Presenter
{
    private User $user;

    public function __construct(User $user)
    {
        $this->user = $user;
    }

    public function startup()
    {
        parent::startup();

        if (!$this->user->isLoggedIn()) {
            // do something
        }
    }
}

@ondrejmirtes
Copy link
Member

@lulco What error are you getting on which line?

@lulco
Copy link
Author

lulco commented Jul 20, 2023

Access to an uninitialized property App\AdminModule\Presenters\AdminPresenter::$user. on line with the if (!$this->user->isLoggedIn()) {

@lulco
Copy link
Author

lulco commented Jul 25, 2023

Do you need some additional information here?

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@1b0c6a0

Please open a new issue next time there's a problem with a closed issue.

@github-actions
Copy link

github-actions bot commented Sep 9, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants