phpstan / phpstan-nette

Nette Framework class reflection extension for PHPStan & framework-specific rules
MIT License
100 stars 35 forks source link

Access to an undefined property Nette\Application\UI\Presenter #16

Closed aleswita closed 6 years ago

aleswita commented 6 years ago

Hi,

any idea, how to fix errors like follow: Access to an undefined property Nette\Application\UI\Presenter::$permission. if I using code below in components? $this->presenter->permission;

ondrejmirtes commented 6 years ago

Hi, which version of nette/application are you using?

aleswita commented 6 years ago

v2.4.9

aleswita commented 6 years ago

For more details, I'm creating components as multiplier


/**
 * @return Nette\Application\UI\Multiplier
 */
protected function createComponentRow(): Nette\Application\UI\Multiplier
{
    return new Nette\Application\UI\Multiplier(function (int $id): App\Module\Components\Row {
        return new App\Module\Components\Row($id);
    });
}
ondrejmirtes commented 6 years ago

There's no property permission or Nette\Application\UI\Presenter, so PHPStan is right here: https://github.com/nette/application/blob/v2.4.9/src/Application/UI/Presenter.php

But I probably understand what's wrong with your code - you need to somehow persuade PHPStan that you're relying on the fact that some of your presenters have the permission property, probably your BasePresenter or something. So you need to put @property MyOwnBasePresenter $presenter in your component (probably App\Module\Components\Row?) or your BaseControl.

aleswita commented 6 years ago

After added annotation to component, problem solved, tnx for help.

github-actions[bot] commented 3 years ago

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.