Closed spaze closed 1 year ago
Because you have template text.latte your presenter also have implicit action Homepage:text that could be invoked. Existence of actionText/renderText methods is not reguired by Nette. And call to this action would cause error in latte.
I would recommend moving setting template parameters to renderDefault/renderText or beforeRender method.
I tried to documented this case here - point 2.
I'm just not sure why it wasn't reported before. Maybe because of old extract($this->params);
call which marks all variables as mixed might not be defined. Now only some variables exists - those which are in array shape. So all other variables are undefined.
Yeah with new version it reports bugs where isset is used with not existing variable. It found few bugs in our code where we checked for wrong variable name in isset. In old version with generic extract any variable could exists so PHPStan ignored these types of errors
I've created example in phpstan playground: https://phpstan.org/r/5947bfc6-71b1-4deb-ae50-ce0df0349c90
I'm closing this as answered. Try to fix in your code or ignore as false positives if you wish.
Because you have template text.latte your presenter also have implicit action Homepage:text that could be invoked. Existence of actionText/renderText methods is not reguired by Nette. And call to this action would cause error in latte.
Oh. OH. OOOOHHHH! π Okay, thanks, that makes sense. I wasn't aware of that behavior even though I've read Nette docs where they mention it, and probably more than once.
Yeah with new version it reports bugs where isset is used with not existing variable.
This is nice and makes sense too and I'm happy it reports it. (Or maybe not, if I have to rewrite something π )
Thanks!
(Have refactored it in spaze/michalspacek.cz#189 to use a service method only to generate a plain text string, not a simple template which now seems like an overkill anyway.)
I was just thinking, could it say something like "rendered from MichalSpacekCz\UpcKeys\Presenters\HomepagePresenter(no action
I was just thinking, could it say something like "rendered from MichalSpacekCz\UpcKeys\Presenters\HomepagePresenter(no action method)" or maybe display an "π‘ error tip Missing action/render, but variable is used in template" and maybe even point to the docs if there's an undefined variable and no action/render method? That would help a lot to at least point me to the right direction.
I think can be added just in top βtableβ where Presenter and action is printed, not as tip for error. We can try something.
AbstractClassStandaloneTemplateResolver now sets name of action to null, we can replace it with template name (+ hint? ) to get something like "AbcPresenter::text.latte(standalone template)"
The error tip with a link would be a nice addition too. The documentation exists, so let's send people there :-)
I'm not able to make it better for now :)
The title may be misleading, sorry, because the variable is not present in older compiled files either, but I don't know what's going on to create a better title π I have read about the "Undefined variable" bc break in the release notes but bear with me.
I have a template
with this relevant PHP code snippet:
After analyzing it with the newly released 0.14.0 I'm now getting:
This has worked before with 0.13.2 (and generally works correctly as the template and the PHP code has not been touched for at least three months).
This is the compiled template:
```php params['filters']; extract($__filters__); /** @var array{baseUrl: string, basePath: string, Κ_fi: Latte\Runtime\FilterInfo, Κ_tag: arrayI have noticed it says
HomepagePresenter
without any action both in the compiled template and in the error message.There's also another compiled file in the temp dir that starts like this:
```php params['filters']; extract($__filters__); /** @var array{baseUrl: string, basePath: string, Κ_fi: Latte\Runtime\FilterInfo, Κ_tag: arraynotice how now it says "HomepagePresenter::default(text)" (and that it also has the ssid variable somewhere in the
@var
block.The temp dir still has some files compiled 3 days ago with the previous version:
```php params); /** @var Nette\Localization\Translator $__filter__translate */ /** @var Closure(mixed, mixed, mixed=): mixed $__filter__modifyDate */ /** @var MichalSpacekCz\Templating\Filters $__filter__staticUrl */ /** @var MichalSpacekCz\Templating\Filters $__filter__staticImageUrl */ /** @var MichalSpacekCz\Templating\Filters $__filter__format */ /** @var MichalSpacekCz\DateTime\DateTimeFormatter $__filter__localeDay */ /** @var MichalSpacekCz\DateTime\DateTimeFormatter $__filter__localeMonth */ /** @var MichalSpacekCz\DateTime\DateTimeFormatter $__filter__localeIntervalDay */ /** @var MichalSpacekCz\DateTime\DateTimeFormatter $__filter__localeIntervalMonth */ $__filters__ = $this->filters->getAll(); /** @var string $baseUrl */ /** @var string $basePath */ /** @var Latte\Runtime\FilterInfo $Κ_fi */ /** @var arrayNotice it also doesn't have any action listed.
Also, there are no files neither forSeems the value in the parentheses doesn't mean what I thought it means, sorry. Seems it's a template/view name, not action params.default(json)
nor fordefault(html)
case, the former may be because there's$this->sendJson()
and it doesn't use any templateThere are files only for (taken from the compiled file docblock):
HomepagePresenter::default
(default.latte.8a701e4616c0d5fbc495115c00d0a4b4.php
)HomepagePresenter::default(text)
(text.latte.ef5361ab21b26118ef97fa4983946a3f.php
)HomepagePresenter
one (text.latte.5a750619f6c72ef76d6013210abd4b2c.php
)Not sure what's going on here :-)