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

n:href="foo => $bar" throws "Offset 0 on array does not exist" #389

Closed
spaze opened this issue Jul 8, 2023 · 1 comment · Fixed by #394
Closed

n:href="foo => $bar" throws "Offset 0 on array does not exist" #389

spaze opened this issue Jul 8, 2023 · 1 comment · Fixed by #394

Comments

@spaze
Copy link
Contributor

spaze commented Jul 8, 2023

I have a template (source) with

<td><small n:tag-if="$application->name === null"><a n:href="Trainings:application $application->id" n:attr="title => $application->company">{$application->name ?? smazáno}</a></small></td>

It gets compiled to

                echo '<a href="';
                /* line 33 */
                /** @var MichalSpacekCz\Admin\Presenters\TrainingsPresenter $adminTrainingsPresenter */
                $adminTrainingsPresenter->actionApplication($application->id);
                echo '"';
                $ʟ_tmp = ['title' => $application->company];
                /* line 33 */
                echo \Latte\Essential\Nodes\NAttrNode::attrs(isset($ʟ_tmp[0]) && \is_array($ʟ_tmp['0']) ? $ʟ_tmp['0'] : $ʟ_tmp, \false);  // <---- line 254
                echo '>';

Analyzing it on level 4 throws

 ------ ---------- ------------------------------------------------------------------------------------------------------------------------------------
  Line   Compiled   Admin/Presenters/templates/Emails/default.latte rendered from MichalSpacekCz\Admin\Presenters\EmailsPresenter::default
         line       See compiled template: /tmp/phpstan-latte/app/Admin/Presenters/templates/Emails/default.latte.933178e70b216f6f964c55e6e984fc7c.php
 ------ ---------- ------------------------------------------------------------------------------------------------------------------------------------
  33     254        Offset 0 on array{title: mixed} in isset() does not exist.
  33     254        Result of && is always false.
 ------ ---------- ------------------------------------------------------------------------------------------------------------------------------------

Another case of the same thing, template with (source):

<small n:class="$storage->getSearchResult()->isSiteUrlMatch($site) ? search-result"><a href="{$site->getUrl()}" n:attr="rel => $noFollow" title="Go to site">{icon link}</a></small>

is compiled to

                     echo '><a href="';
                    /* line 56 */
                    echo \Latte\Runtime\Filters::escapeHtmlAttr(\Latte\Runtime\Filters::safeUrl($site->getUrl()));
                    echo '"';
                    $ʟ_tmp = ['rel' => $noFollow];
                    /* line 56 */
                    echo \Latte\Essential\Nodes\NAttrNode::attrs(isset($ʟ_tmp[0]) && \is_array($ʟ_tmp['0']) ? $ʟ_tmp['0'] : $ʟ_tmp, \false);  <--- line 516
                    echo ' title="Go to site">';

Throws:

 ------ ---------- -----------------------------------------------------------------------------------------------------------------------------------------------
  Line   Compiled   Pulse/Presenters/templates/PasswordsStorages/default.latte rendered from MichalSpacekCz\Pulse\Presenters\PasswordsStoragesPresenter::default
         line       See compiled template: /tmp/phpstan-latte/app/Pulse/Presenters/templates/PasswordsStorages/default.latte.b6bb0c039f77aca94a2c1dc7262492e8.php
 ------ ---------- -----------------------------------------------------------------------------------------------------------------------------------------------
[...]
  56     516        Offset 0 on array{rel: 'nofollow'|false} in isset() does not exist.
  56     516        Result of && is always false.
@lulco
Copy link
Contributor

lulco commented Jul 8, 2023

This is some nette thing we should transform before phpstan check. Thanks for report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants