Deprecating PHP4 style constructors in WordPress 4.3

PHP7 is slated for release later this year. One of the changes is that PHP4 style constructors are deprecated. In order to prepare WordPress to support PHP7, these constructors have been deprecated in WordPress coreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress.. This is a quick guide to all you need to know about this change.

What are PHP4 style constructors?

Prior to the introduction of __construct in PHP5, classes were constructed by using a method with the same name as the class.  For example:

class Yo {
    function yo(){
        // code that constructs our class

PHP5 added __construct, but it also continued to allow the PHP4 style constructors, but with some evolving (and occasionally confusing) rules related to the presence of __construct, the ordering of the methods, and if a class is within a namespace.

What is WordPress Doing

r32990 introduced a change so that all classes use the PHP5 style constructors, while still retaining the PHP4 style constructors for backwards compatibility. For WordPress classes (not external libraries), a deprecated_constructor warning that follows the same rules as deprecated_function will also be displayed. This is designed to help ease the transition to PHP7.

What should you do?

If you are sub classing a WordPress class and calling the PHP4 constructor, you should update your code to use parent::__construct instead. You should also audit your own code to make sure it is using PHP5 style constructors.

PHP7 is promising some very impressive performance improvements, and I’m excited to see it get closer and closer to release.   If you have any questions on this change, please comment below.

Update: A list of affected plugins that call WP_Widget::WP_Widget() or parent::WP_Widget() is here.

#4-3, #dev-notes, #php7