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

"Key not defined" compile time related issue with sysplugins/smarty_internal_debug.php #674

Closed
ophian opened this issue Aug 17, 2021 · 4 comments

Comments

@ophian
Copy link

ophian commented Aug 17, 2021

I have found a certain use case where $this->template_data[ $this->index ][ $key ][ 'start_template_time' ] at L 73 and $this->template_data[ $this->index ][ $key ][ 'start_time' ] at L 146 'start_...' keys were not defined. (Smarty current)

This is caused by using debugging = true; in my Smarty class and it does not fail by using {debug} in a template file otherwise.
I couldn't find out yet which specific template call is the root cause for further debugging, since this does not happen everywhere.
Temporarily I put both into a ($foo ?? 0) PHP 7 ternary, which helps since I do only support up from.

So maybe someone can confirm this issue and we can nail it without suppressing the warnings.
(Using PHP 8 in a "personal" debug mode.)

Edit: I found the #266 issue, which is describing the same.
The difference, I do not use {eval} in templates, but there is one $smarty->display('eval:'.$content); around in install cases only, which actually should not interfere here.

@wisskid
Copy link
Contributor

wisskid commented Aug 18, 2021

Please try #629 and use the Smarty::muteUndefinedOrNullWarnings method.

@wisskid wisskid closed this as completed Aug 18, 2021
@scottchiefbaker
Copy link

I'm testing #629 and I have the following in my template:

<div class="{if $TPL_FULL_WIDTH}container-fluid{else}container-lg{/if} mt-3">

Which is generating the following TPL output:

<div class="<?php if ($_smarty_tpl->tpl_vars['TPL_FULL_WIDTH']->value) {?>container-fluid<?php } else { ?>container-lg<?php }?> mt-3">

Which results in a Attempt to read property "value" on null error. Is this the same thing as this issue or something separate?

@scottchiefbaker
Copy link

Using the branch from #629 the follow silenced the above error I mentioned.

$smarty->muteUndefinedOrNullWarnings(true)

It's worth noting that you can also do:

$smarty->error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING

On Smarty 3.x if you just want to get around this on the older smarty until 4.x can be released. It's not an ideal solution, but it works.

@ophian
Copy link
Author

ophian commented Aug 19, 2021

As I said, I do not want to just suppress or mute the warning since I want to see them happen while this is a strong and valid debug mode case of my environment. Smarty should not mute by itself. Also see the other mentioned issue ref (including comments) in my first post.

I think this should be fixable. I followed Uwes first fix and saw that in some follow up commits he cleaned up and refactored related things. So I think it has to do with using debugging === 2 and display() or fetch() and could be related to a sub-template usage. (AND/or PHP 8 strict types)

I already did some further tests in both render() methods of the smarty_internal_template and smarty template_compiled files and found that in my case it is the fetch() fallback and there specifically a certain "middle" template, being some sort of a sub-template, called twice and the first one being empty on those index keys throwing these warnings.

After several test sessions i currently came up with adding these !isset return checks

    /**
     * End logging of cache time
     *
     * @param \Smarty_Internal_Template $template cached template
     */
    public function end_template(Smarty_Internal_Template $template)
    {
        $key = $this->get_key($template);
        if (!isset($this->template_data[ $this->index ][ $key ][ 'start_template_time' ])) return;// also see internal_template L 243

and

    /**
     * End logging of compile time
     *
     * @param \Smarty_Internal_Template $template
     */
    public function end_render(Smarty_Internal_Template $template)
    {
        $key = $this->get_key($template);
        if (!isset($this->template_data[ $this->index ][ $key ][ 'start_time' ])) return; // see template_compiled L 119

for the moment.

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

No branches or pull requests

3 participants