【问题标题】:Warnings with Smarty after upgrade to PHP 7.0.8升级到 PHP 7.0.8 后 Smarty 的警告
【发布时间】:2016-07-09 10:25:57
【问题描述】:

将 Plesk 和 PHP 升级到版本 7.0.8 后,我在使用 Smarty 时收到以下警告。

不推荐使用 PHP:与其类同名的方法在 PHP 的未来版本中将不再是构造函数; Smarty_Compiler 在第 35 行的 /var/www/vhosts/mydomain.com/httpdocs/Smarty/Smarty_Compiler.class.php 中有一个已弃用的构造函数

这里是警告中提到的文件:

/*
 * @link http://smarty.php.net/
 * @author Monte Ohrt <monte at ohrt dot com>
 * @author Andrei Zmievski <andrei@php.net>
 * @version 2.6.20
 * @copyright 2001-2005 New Digital Group, Inc.
 * @package Smarty
 */

/* $Id: Smarty_Compiler.class.php 2773 2008-08-12 18:17:51Z Uwe.Tews $ */

/**
 * Template compiling class
 * @package Smarty
 */
class Smarty_Compiler extends Smarty {

我需要帮助来了解问题以及如何解决它,它是相对于 Smarty 还是可以解决?

【问题讨论】:

  • 分享更多信息请喜欢你现在的php版本是什么?并分享完整的错误信息。
  • AH01071: Got error 'PHP message: PHP Deprecated: Method with the same name as their class will not be constructors in the future version of PHP; Smarty_Compiler 在第 35 行的 /var/www/vhosts/mydomain.com/httpdocs/Smarty/Smarty_Compiler.class.php 中有一个已弃用的构造函数\n'
  • 运行 PHP 7.0.8 版
  • 我编辑了您问题的标题,以包含有关您的警告的更多信息,例如您刚刚更新到的 PHP 版本。我也在问题中添加了您在 cmets 中提供的所有新信息并改进了格式。祝你好运!

标签: php smarty


【解决方案1】:

PHP 7.0.x 开始,PHP 4 style constructors (methods that have the same name as the class they are defined in) 已被弃用,并将在未来被删除。如果 PHP 4 构造函数是类中定义的唯一构造函数,则 PHP 7 将发出 E_DEPRECATED。实现 __construct() 方法的类不受影响。

所以,有两种解决方案:

  1. 您可以通过在代码中添加以下内容来关闭已弃用的警告消息: error_reporting(E_ALL ^ E_DEPRECATED);

  2. 编辑Smarty_Compiler.class.php文件并将方法名称Smarty_Compiler()更改为__construct()

【讨论】:

  • class Smarty_Compiler extends Smarty { // 内部变量 /**#@+ * @access private / /**#@-*/ /* * 类构造函数。 */ function Smarty_Compiler() {
  • 是的,将function Smarty_Compiler() 重命名为function __construct()
  • 它有效。我在两个文件中更改了它:Smarty_Compiler... 和 Smarty...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-02
  • 1970-01-01
  • 1970-01-01
  • 2017-01-11
  • 1970-01-01
  • 2021-06-28
  • 1970-01-01
相关资源
最近更新 更多