自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

相关文章

我们有时候在定制WORDPRESS主题的时候,由于菜单样式的要求我...
很多朋友在做wordpree主题制作的时候会经常遇到一个问题,那...
wordpress后台的模块很多,但并不是每个都经常用到。介绍几段...
从WordPress4.2版本开始,如果我们在MYSQL5.1版本数据中导出...
很多网友会遇到这样一个问题,就是WordPress网站上传图片、附...
对于经常要在文章中出现代码的IT相关博客,安装一个代码高亮...