我有一个现有的,功能良好的PHP应用程序。我正在研究服务器升级,其中包括从PHP5迁移到PHP7。据我所知,从文档中可以看出Smarty3应该与PHP7兼容。但是,在测试时,Smarty在升级后拒绝编译模板。
问题的根源似乎是这条线:
$this->smarty->registerPlugin('compiler', 'asset_url', array(&$this, 'asset_url'));这会导致PHP应用程序崩溃,如下所示:
Notice: Array to string conversion in /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php on line 415
Notice: Undefined property: template::$Array in /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php on line 415
Fatal error: Uncaught Error: Function name must be a string in /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php:415
Stack trace:
#0 /usr/share/php/smarty3/sysplugins/smarty_internal_templateparser.php(3585): Smarty_Internal_TemplateCompilerBase->compileTag('asset_url', Array)
#1 /usr/share/php/smarty3/sysplugins/smarty_internal_templateparser.php(4413): Smarty_Internal_Templateparser->yy_r32()
#2 /usr/share/php/smarty3/sysplugins/smarty_internal_templateparser.php(4515): Smarty_Internal_Templateparser->yy_reduce(32)
#3 /usr/share/php/smarty3/sysplugins/smarty_internal_smartytemplatecompiler.php(118): Smarty_Internal_Templateparser->doParse(3, '}')
#4 /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php(283): Smarty_Internal_SmartyTemplateCompiler->doCompile('<!DOCTYPE html>...')
#5 /usr/share/php/smarty3/sysplugins/smarty_internal_template.php(197): Smarty_Internal_TemplateCompilerBase->compileTemplate(Object(Smarty_Internal_Template))
#6 /usr/share/php/smarty3/sysplugins/sm in /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php on line 415可疑线路415如下所示:
$function = $this->smarty->registered_plugins[$plugin_type][$tag][0];
if (!is_array($function)) {
return $function($new_args, $this);
} elseif (is_object($function[0])) {
return $this->smarty->registered_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this); <- Crash here!
} else {
return call_user_func_array($function, array($new_args, $this));
}我想这是PHP5和PHP7之间的一些基本区别,这让我很难受,但我似乎不知道它是什么。有谁能给我一些关于如何解决这个问题的建议?
发布于 2016-05-24 13:26:04
如果您使用的是旧版本的Smarty,您可能需要更新。在3.1.28中添加了一些PHP 7兼容性的补丁,这可能会对此有所帮助。
请参阅log.txt
发布于 2018-10-11 13:28:47
对这个问题的解释(除了“您有一个过时的版本”这类最常见的问题)是,在PHP 7中,代码的解析方式已经发生了变化。就你而言:
$this->smarty->registered_plugins[$plugin_type][$tag][0];
是PHP 5和7中的不同解析
PHP5:$this->smarty->{registered_plugins[$plugin_type][$tag][0]};
PHP7:($this->smarty->registered_plugins)[$plugin_type][$tag][0];
您可以尝试修复这些代码片段,方法是放置大括号和括号,以指示解析器您的确切意图,但我建议您升级Smarty。
https://stackoverflow.com/questions/37411878
复制相似问题