升级到 PHP 7.0.8 后 Smarty 的警告

Warnings with Smarty after upgrade to PHP 7.0.8

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

PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Smarty_Compiler has a deprecated constructor in /var/www/vhosts/mydomain.com/httpdocs/Smarty/Smarty_Compiler.class.php on line 35

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

/*
 * @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 7.0.x 起,PHP 4 style constructors (methods that have the same name as the class they are defined in) 已弃用,将来会被删除。如果 PHP 4 构造函数是 class 中定义的唯一构造函数,PHP 7 将发出 E_DEPRECATED。 类 实现 __construct() 方法不受影响。

所以,有两个解决方案:

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

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