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

旧城冷巷雨未停 提交于 2019-12-17 17:16:03

问题


I am trying to upgrade the PHP version of my WP site which is hosted on SiteGround. Upgrader tool shows this error:

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

This is the code I found at the given location:

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

How do I fix that?


回答1:


Change the function to:

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

As you used to be able to define constructors via the class name and that has been deprecated as of 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.

The error example, as per the documentation:

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



来源:https://stackoverflow.com/questions/50784934/use-of-deprecated-php4-style-class-constructor-is-not-supported-since-php-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!