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

后端 未结 1 1797
野的像风
野的像风 2020-12-22 11:01

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 P

相关标签:
1条回答
  • 2020-12-22 11:27

    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

    0 讨论(0)
提交回复
热议问题