自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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...