Danko Danko - 4 months ago 51
PHP Question

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.


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


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?

Answer

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 will emit E_DEPRECATED if a PHP 4 constructor is the only constructor defined within a class. Classes that implement a __construct() method are unaffected.

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);

  2. Edit the Smarty_Compiler.class.phpfile and change the method name Smarty_Compiler() to __construct()