首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Smarty3升级到PHP7和注册插件的奇怪问题

Smarty3升级到PHP7和注册插件的奇怪问题
EN

Stack Overflow用户
提问于 2016-05-24 11:11:31
回答 2查看 3.6K关注 0票数 1

我有一个现有的,功能良好的PHP应用程序。我正在研究服务器升级,其中包括从PHP5迁移到PHP7。据我所知,从文档中可以看出Smarty3应该与PHP7兼容。但是,在测试时,Smarty在升级后拒绝编译模板。

问题的根源似乎是这条线:

代码语言:javascript
复制
$this->smarty->registerPlugin('compiler', 'asset_url',  array(&$this, 'asset_url'));

这会导致PHP应用程序崩溃,如下所示:

代码语言:javascript
复制
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如下所示:

代码语言:javascript
复制
 $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之间的一些基本区别,这让我很难受,但我似乎不知道它是什么。有谁能给我一些关于如何解决这个问题的建议?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-05-24 13:26:04

如果您使用的是旧版本的Smarty,您可能需要更新。在3.1.28中添加了一些PHP 7兼容性的补丁,这可能会对此有所帮助。

请参阅log.txt

票数 2
EN

Stack Overflow用户

发布于 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。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37411878

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档