自PHP 7起,不支持使用弃用的PHP4样式类构造函数

我正在尝试升级我在SiteGround上托管的WP站点的PHP版本.升级工具显示此错误:

33 | WARNING | Use of deprecated PHP4 style class constructor is not
supported since PHP 7

这是我在给定位置找到的代码:

function gc_XmlBuilder($indent = '  ') {
  $this->indent = $indent;
  $this->xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
}

我该如何解决这个问题?

解决方法:

将功能更改为:

function __construct($indent = '  ') {
  $this->indent = $indent;
  $this->xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
}

您以前可以通过类名定义构造函数,并且从PHP 7开始已弃用:

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.

错误示例,根据文档:

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; foo has a deprecated constructor in example.php on line 3

上一篇:Android Studio中的错误警告


下一篇:php – 您的SQL语法有错误;查看与MariaDB服务器版本对应的手册,以获取正确的语法