PHP 4 Style Constructors Are Being Deprecated in WordPress 4.3

Last updated on by admin


PHP 7 is expected to release later this year. One of the major changes in PHP 7 is that PHP 4 style constructors are deprecated. In order to prepare WordPress to transition to PHP 7, WordPress is deprecating these constructors in 4.3.

PHP 4 Style Constructors

In PHP 4 classes are constructed by using a method with same name as the class. For example:

class Test {
    function Test( ){
        // code to construct the class
    }
}

PHP 5 Style Constructors

PHP 5 introduced __construct, but continued to support PHP 4 style constructors for backwards compatibility. For example:

class Test {
    function __construct( ){
        // code to construct the class
    }
}

Upcoming Changes in WordPress Core

As of 4.3, WordPress will display a deprecated_constructor warning if PHP 4 style constructors are detected. If you are sub classing a WordPress class by using the PHP 4 style constructor, you should update the code to use parent::__construct instead.

special SiteGround WordPress hostingspecial Bluehost WordPress hosting

Leave a Reply

Your email address will not be published. Required fields are marked *