thePHP.cc Logo Deutsch Contact
PHP Breaks Backwards Compatibility

PHP Breaks Backwards Compatibility

According to the PHP project's current time line, PHP 7 is scheduled to be released later this year . The version number 6 will be skipped for good reasons .

As is expected of a new major release, there will be some breaks in backwards compatibility. Such breaks are always a double-edged sword: some have been eagerly awaiting the removal of legacy features, others expect that existing software keeps working without modifications.

The PHP project is notorious for keeping some sins of the past dating back to PHP 3 in an effort to ensure backwards compatibility. Now, with the release of PHP 7, the decision has been made to remove some features that have been marked as deprecated in PHP 5.

The Zend Engine, PHP's compiler and executor, will be re-engineered for PHP 7. This is important, since nowadays HHVM is more and more becoming a viable alternative to PHP by offering better performance and using fewer resources to execute PHP code. Re-engineering thus is crucial for the PHP project, unless they want to risk losing their position as the leading programming language for the web.

Re-Engineering PHP

This re-engineering will result in a few changes to the behavior , for example in nested variable access such as $$foo['bar']['baz'] or Foo::$bar['baz']() . Currently, a statement like global $$foo->bar; is allowed in PHP. For PHP 7 it has to be rewritten as global ${$foo->bar}; .

Changes like these break Magento 1 on PHP 7. One could certainly have a rather controversial debate about the question whether such statements should be used at all. After all, they are really hard to understand. But then again, the problem is already known, and the changes mentioned above have already been decided in June 2014. It should not be a big problem to start converting existing code step by step, and start with this today.

PHP 5 was released in 2004. It took a very long time until this version was widely adopted in the field. Most PHP installations, even a few years after 2004, still operated using PHP 4. The reason was kind of a cyclic dependency: well-known projects supported PHP 4, so they were run on a PHP 4 platform. Since this was the case, many Open Source projects did not bother raising their system requirements to PHP 5, and they chose not to make use of the new PHP 5 features like the support for "real" object-orientation.

Many projects only started to deal with the possibilities of the new version when the PHP project announced that the development of PHP 4 would cease. Using the mysqli extension instead of the mysql extension is a good example for this. Though mysql was not marked as deprecated until PHP 5.5, mysqli has been available since PHP 5.0 and Sun (or Oracle, respectively) have been stressing for a long time that mysqli is the preferred way of connecting tom MySQL from PHP.

PHP core developer and Oracle employee Johannes Schlüter wrote already back in 2011:

Moving away from ext/mysql is not only about security but also about having access to all features of the MySQL database.

Some background on this: the mysql extension is based on the state-of-the-art of MySQL 3.23, which had been released as early as 2001. PHP 7 will be shipped without the mysql extension.

PEAR stopped working

Quite recently, the PEAR environment stopped working with PHP 7. The problem is that PEAR calls non-static methods statically. Doing this has only been deprecated in PHP 5.6 last year, but has been raising an E_STRICT warning for years. There would have been more than enough time to adapt the code accordingly. Since the PEAR Installer gets distributed with PHP and a missing PEAR Installer leads to problems with testing PHP itself, the backwards compatibility-breaking change has been reverted in PHP 7 for now. Let us hope that this is only a temporary fix and the PEAR project will soon adapt their code to PHP 7.

The automotive industry faces new and stricter exhaust emission standards rather frequently. This means that either old cars will need remodeling, or limitations in use will result. The situation for buildings are similar. Energy and security standards are tightened from time to time, which makes refurbishings and renovations necessary. The same holds true for software. The release of PHP 7 neither means that PHP 5 stops working nor does it imply that one could not invest time and put work into making existing software work on PHP 7.

The PHP project is right in their decision to break backwards compatibility with the release of PHP 7. Any product, hardware or software, has a life cycle and a limited lifespan. After more than 10 years no PHP user can expect to benefit from a major update of the language with significant performance improvements without putting any effort into the upgrade.