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

Compiler bug in Smarty 3.1.30 #293

Closed
mreiche opened this issue Sep 15, 2016 · 6 comments
Closed

Compiler bug in Smarty 3.1.30 #293

mreiche opened this issue Sep 15, 2016 · 6 comments

Comments

@mreiche
Copy link

mreiche commented Sep 15, 2016

I'm running in compiler bugs when I upgrade from Smarty 3.1.29 to Smarty 3.1.30. The compiled templates got syntax errors:

( ! ) Parse error: syntax error, unexpected '=' in /var/cache/smarty/compiled/ed6fe7ac864d566ddc843adfdd232d373de4d144_0.file.headline_top.tpl.php on line 60
<?php $_block_repeat-1=false;
echo smarty\plugins\ContentBlock::renderBlock(array('id'=>"text"), ob_get_clean(), $_smarty_tpl, $_block_repeat-1);

ContentBlock

public static function renderBlock($params, $content, Smarty_Internal_Template $template, &$repeat) {
// $repeat is unused, not read or written
}
@uwetews
Copy link
Contributor

uwetews commented Sep 15, 2016

Hmm
From the small section of compiled code it looks like that you did use a default plugin handler.
Is that true? if yes please provide its code.
Also could you provide the section of compiled code where smarty\plugins\ContentBlock::renderBlock()
was called the first time?
Did you use nested block plugins?
If you delete the compiled template file is the error reoccurring?
Anyway it does look like that the block plugin compiler was called in some strange was that the invalid variable name $_block_repeat-1 was generated.

Note: I will be traveling for a week and it's not guaranteed that I have Internet access during that time. :(

@mreiche
Copy link
Author

mreiche commented Sep 16, 2016

Good morning.

From the small section of compiled code it looks like that you did use a default plugin handler.
Is that true? if yes please provide its code.

Here is my code, slightly changed to hide the vendor.

abstract class ATemplateRenderer extends Smarty {
    private $_pluginNamespaces = null;
    public function __construct() {
        parent::__construct();
        /**
         * We have to set this option to false to allow includes with dynamic within blocks
         * This restriction should be removed in Smarty 3.2
         * @see http://www.smarty.net/forums/viewtopic.php?p=86927
         */
        $this->inheritance_merge_compiled_includes = false;
        $this->registerDefaultPluginHandler(array($this, '__pluginHandler'));
    }
    public function __pluginHandler($name, $type, $template, &$callback, &$script, &$cacheable) {
        if ($this->_pluginNamespaces === null) {
            /**
             * Load all plugin namespaces from definition files
             */
            $this->loadPluginConfiguration();
        }
        /**
         * Find plugin for namespace
         * {namespace_plugin} -> namespace\PluginFunction::renderFunction()
         * {namespace_plugin}{/namespace_plugin} -> namespace\PluginBlock:::renderBlock()
         * {$var|namespace_plugin} -> namespace\PluginModifier::renderModifier()
         */
        $parts = explode('_', $name);
        if (array_key_exists($parts[0], $this->_pluginNamespaces)) {
            $namespace = $parts[0];
            unset($parts[0]);
            $ucType = ucfirst($type);
            $pluginClass = join('',array_map('ucfirst',$parts)).$ucType;
            $pluginFile = $this->_pluginNamespaces[$namespace][0].$pluginClass.'.php';
            if (file_exists($pluginFile)) {
                $script = $pluginFile;
                $callback = $this->_pluginNamespaces[$namespace][1].$pluginClass.'::render'.$ucType;
                return true;
            }
        }
        return false;
    }
}

Did you use nested block plugins?

Regulary, a block named AreaBlock contains multiple ContentBlocks.

If you delete the compiled template file is the error reoccurring?

Yes

Also could you provide the section of compiled code where smarty\plugins\ContentBlock::renderBlock()
was called the first time?

The error message:

Parse error: syntax error, unexpected '=' in /var/cache/smarty/compiled/606f30631f6e42c7da96ae6ffe59bba97b942985_0.file.smarty-base.tpl.php on line 283

cat 606f30631f6e42c7da96ae6ffe59bba97b942985_0.file.smarty-base.tpl.php | grep renderBlock -A 2 -B 2

The compiled file (I removed the vendor namespace)

if (!is_callable('smarty\plugins\SeoBlock::renderBlock')) require_once 'xxx/smarty/plugins/SeoBlock.php';
if (!is_callable('smarty\plugins\StyleCollectionFunction::renderFunction')) require_once 'xxx/smarty/plugins/StyleCollectionFunction.php';
if (!is_callable('smarty\plugins\OutputBlockFunction::renderFunction')) require_once 'xxx/smarty/plugins/OutputBlockFunction.php';
--
if (!is_callable('smarty\plugins\SiterolesSubjectFunction::renderFunction')) require_once 'xxx/smarty/plugins/SiterolesSubjectFunction.php';
if (!is_callable('smarty\plugins\UriFunction::renderFunction')) require_once 'xxx/smarty/plugins/UriFunction.php';
if (!is_callable('smarty\plugins\ScriptBlock::renderBlock')) require_once 'xxx/smarty/plugins/ScriptBlock.php';
if (!is_callable('smarty\plugins\ContentBlock::renderBlock')) require_once 'xxx/smarty/plugins/ContentBlock.php';
if (!is_callable('smarty\plugins\NavigationFunction::renderFunction')) require_once 'xxx/smarty/plugins/NavigationFunction.php';
if (!is_callable('smarty\plugins\OembedBlock::renderBlock')) require_once 'xxx/smarty/plugins/OembedBlock.php';
if (!is_callable('smarty\plugins\FilesBlock::renderBlock')) require_once 'xxx/smarty/plugins/FilesBlock.php';
if (!is_callable('smarty\plugins\ImageFunction::renderFunction')) require_once 'xxx/smarty/plugins/ImageFunction.php';
if (!is_callable('smarty\plugins\AreaBlock::renderBlock')) require_once 'xxx/smarty/plugins/AreaBlock.php';
if (!is_callable('smarty\plugins\ScriptCollectionFunction::renderFunction')) require_once 'xxx/smarty/plugins/ScriptCollectionFunction.php';
$_smarty_tpl->_loadInheritance();
--
        <?php $_smarty_tpl->smarty->_cache['_tag_stack'][] = array('xxx_seo', array());
$_block_repeat1=true;
echo smarty\plugins\SeoBlock::renderBlock(array(), null, $_smarty_tpl, $_block_repeat1);
while ($_block_repeat1) {
ob_start();
--

        <?php $_block_repeat1=false;
echo smarty\plugins\SeoBlock::renderBlock(array(), ob_get_clean(), $_smarty_tpl, $_block_repeat1);
}
array_pop($_smarty_tpl->smarty->_cache['_tag_stack']);?>
--
                                <?php $_smarty_tpl->smarty->_cache['_tag_stack'][] = array('xxx_script', array('name'=>"xxx",'uid'=>"xxx"));
$_block_repeat1=true;
echo smarty\plugins\ScriptBlock::renderBlock(array('name'=>"xxx",'uid'=>"xxx"), null, $_smarty_tpl, $_block_repeat1);
while ($_block_repeat1) {
ob_start();
--

                                <?php $_block_repeat1=false;
echo smarty\plugins\ScriptBlock::renderBlock(array('name'=>"xxx",'uid'=>"xxx"), ob_get_clean(), $_smarty_tpl, $_block_repeat1);
}
array_pop($_smarty_tpl->smarty->_cache['_tag_stack']);?>
--
                                <h2><?php $_smarty_tpl->smarty->_cache['_tag_stack'][] = array('xxx_content', array('global'=>"client",'id'=>"smarty_template"));
$_block_repeat1=true;
echo smarty\plugins\ContentBlock::renderBlock(array('global'=>"client",'id'=>"smarty_template"), null, $_smarty_tpl, $_block_repeat1);
while ($_block_repeat1) {
ob_start();
?>
Client-global<?php $_block_repeat1=false;
echo smarty\plugins\ContentBlock::renderBlock(array('global'=>"client",'id'=>"smarty_template"), ob_get_clean(), $_smarty_tpl, $_block_repeat1);
}
array_pop($_smarty_tpl->smarty->_cache['_tag_stack']);?>
--
                                <p><?php $_smarty_tpl->smarty->_cache['_tag_stack'][] = array('xxx_content', array('global'=>"all",'id'=>"superglobal",'html'=>"inline",'description'=>"Superglobale Begrüßungstext"));
$_block_repeat1=true;
echo smarty\plugins\ContentBlock::renderBlock(array('global'=>"all",'id'=>"superglobal",'html'=>"inline",'description'=>"Superglobale Begrüßungstext"), null, $_smarty_tpl, $_block_repeat1);
while ($_block_repeat1) {
ob_start();
?>
Superglobal<?php $_block_repeat0=false;
echo smarty\plugins\ContentBlock::renderBlock(array('global'=>"all",'id'=>"superglobal",'html'=>"inline",'description'=>"Superglobale Begrüßungstext"), ob_get_clean(), $_smarty_tpl, $_block_repeat0);
}
array_pop($_smarty_tpl->smarty->_cache['_tag_stack']);?>
--
                        <?php $_smarty_tpl->smarty->_cache['_tag_stack'][] = array('xxx_oembed', array('src'=>"https://youtu.be/xxx"));
$_block_repeat0=true;
echo smarty\plugins\OembedBlock::renderBlock(array('src'=>"https://youtu.be/xxx"), null, $_smarty_tpl, $_block_repeat0);
while ($_block_repeat0) {
ob_start();
--

                        <?php $_block_repeat0=false;
echo smarty\plugins\OembedBlock::renderBlock(array('src'=>"https://youtu.be/xxx"), ob_get_clean(), $_smarty_tpl, $_block_repeat0);
}
array_pop($_smarty_tpl->smarty->_cache['_tag_stack']);?>
--
                        <?php $_smarty_tpl->smarty->_cache['_tag_stack'][] = array('xxx_files', array('directory_ids'=>array(320),'mimetypes'=>array('image/%')));
$_block_repeat0=true;
echo smarty\plugins\FilesBlock::renderBlock(array('directory_ids'=>array(320),'mimetypes'=>array('image/%')), null, $_smarty_tpl, $_block_repeat0);
while ($_block_repeat0) {
ob_start();
--

                        <?php $_block_repeat0=false;
echo smarty\plugins\FilesBlock::renderBlock(array('directory_ids'=>array(320),'mimetypes'=>array('image/%')), ob_get_clean(), $_smarty_tpl, $_block_repeat0);
}
array_pop($_smarty_tpl->smarty->_cache['_tag_stack']);?>
--
                                <h3><?php $_smarty_tpl->smarty->_cache['_tag_stack'][] = array('xxx_content', array('id'=>"headline"));
$_block_repeat2=true;
echo smarty\plugins\ContentBlock::renderBlock(array('id'=>"headline"), null, $_smarty_tpl, $_block_repeat2);
while ($_block_repeat2) {
ob_start();
?>
Überschrift<?php $_block_repeat-1=false;
echo smarty\plugins\ContentBlock::renderBlock(array('id'=>"headline"), ob_get_clean(), $_smarty_tpl, $_block_repeat-1);
}
array_pop($_smarty_tpl->smarty->_cache['_tag_stack']);?>
--
                                <?php $_smarty_tpl->smarty->_cache['_tag_stack'][] = array('xxx_area', array('id'=>"test"));
$_block_repeat-1=true;
echo smarty\plugins\AreaBlock::renderBlock(array('id'=>"test"), null, $_smarty_tpl, $_block_repeat-1);
while ($_block_repeat-1) {
ob_start();
--

                                <?php $_block_repeat-1=false;
echo smarty\plugins\AreaBlock::renderBlock(array('id'=>"test"), ob_get_clean(), $_smarty_tpl, $_block_repeat-1);
}
array_pop($_smarty_tpl->smarty->_cache['_tag_stack']);?>

@uwetews
Copy link
Contributor

uwetews commented Sep 20, 2016

Okay I think I'm getting closer. I see that you are using template inheritance.
Do you have any block plugin open and close tags which are in different inheritance {block}{/block} or worse could the plugin open and the close tag be executed by inheritance blocks in different template files?
Could you please send me the template code (private uwe.tews@googlemail.com)
There is a temporary patch in dev master. you should no longer see errors. But this is just now. so I must find out the root cause

@mreiche
Copy link
Author

mreiche commented Oct 5, 2016

Did you receive my email?

@uwetews
Copy link
Contributor

uwetews commented Oct 23, 2016

I had received your email.
Did you try the master branch version? does it solve your problem?

@mreiche
Copy link
Author

mreiche commented Mar 2, 2017

This compiler bug seems to be fixed in smarty/smarty:dev-master.

@mreiche mreiche closed this as completed Mar 2, 2017
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

2 participants