简体   繁体   English

升级到PHP 7.0.8后使用Smarty发出警告

[英]Warnings with Smarty after upgrade to PHP 7.0.8

After upgrading Plesk and PHP to the version 7.0.8, I'm getting the following warning when using Smarty. 将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; 不推荐使用PHP:与它们的类同名的方法在将来的PHP版本中将不再是构造函数。 Smarty_Compiler has a deprecated constructor in /var/www/vhosts/mydomain.com/httpdocs/Smarty/Smarty_Compiler.class.php on line 35 Smarty_Compiler在第35行的/var/www/vhosts/mydomain.com/httpdocs/Smarty/Smarty_Compiler.class.php中已弃用构造函数

Here the file mentioned in the warning: 这里是警告中提到的文件:

/*
 * @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 {

I need help to understand the problem and how to fix it, is it relative to Smarty or fixable on my end? 我需要帮助来了解问题以及如何解决它,这相对于Smarty还是可以修复的?

As of PHP 7.0.x , PHP 4 style constructors (methods that have the same name as the class they are defined in) are deprecated, and will be removed in the future. PHP 7.0.x ,不赞成使用PHP 4 style constructors (methods that have the same name as the class they are defined in) ,并将在将来删除。 PHP 7 will emit E_DEPRECATED if a PHP 4 constructor is the only constructor defined within a class. 如果PHP 4构造函数是类中唯一定义的构造函数,则PHP 7将发出E_DEPRECATED Classes that implement a __construct() method are unaffected. 实现__construct()方法的类不受影响。

So, there's two solution: 因此,有两种解决方案:

  1. You can turn off the deprecated warning message by adding this on your code: error_reporting(E_ALL ^ E_DEPRECATED); 您可以通过在代码中添加以下内容来关闭已弃用的警告消息: error_reporting(E_ALL ^ E_DEPRECATED);

  2. Edit the Smarty_Compiler.class.php file and change the method name Smarty_Compiler() to __construct() 编辑Smarty_Compiler.class.php文件,并将方法名称Smarty_Compiler()更改为__construct()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM