微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

自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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐