WordPress and PHP7

For the last few months, WordPress Core has been getting ready for the upcoming release of PHP7. PHP7 is bringing a host of improvements to PHP. One of the most notably is substantial performance improvements.Benchmarks of WordPress using PHP7 are showing a 2-3x speed improvement compared to PHP5.6.

The first step towards support for PHP7 was to add PHP7 nightlies to the automated test matrix. For six months, WordPress has been testing every commit against PHP7. This helped us uncover a couple of now fixed issues.

For example, PHP7 deprecates PHP4 style constructors. Therefore, WordPress Core removed them and also added a deprecation notice to all themes and plugins using them to extend core classes. This is done to help ensure that as many themes and plugins as possible are ready for PHP7.

Next, WordPress Core fixed a small number of issues related to the Uniform Variable Syntax changes in PHP7.  Plugin and Theme authors are strongly encouraged to familiarize themselves with this change and all other backwards incompatible changes.

PHP7 is currently targeted for release on November 12, 2015. Coincidentally, this is also the date that WordPress intends to officially fully support PHP7. 😃 While WordPress doesn’t officially support unreleased versions of PHP, you are encouraged to test and report any issues you find with PHP7 before the its official release.  PHP7 builds are available for Ubuntu 14.04 and CentOS 7 (and compatible distros) from php7.zend.com.

Even as WordPress Core continues to expand its support for new versions of PHP, we have no intention of abandoning support for older versions until usage numbers show that the impact on users will be minimal. WordPress will continue to work with hosting providers to encourage them to upgrade their users to a current version of PHP and, when it’s reasonable, we will consider raising our minimum requirements. Regardless, WordPress continues to encourage all users to run the latest and greatest versions of PHP, including PHP7 upon its release.

#php7

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 core. 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