PHP, like all software, keeps on evolving, with every new release bringing in new features. In between the major releases are minor releases that mainly fix bugs and make a few minor tweaks.
In August 2014, after a lot of discussion and voting, the PHP community decided on PHP 7 as the next major version of PHP. While this is normal, what is of interest is that PHP 7 would replace PHP 5.x, and a major point of discussion was on whether to name the new update as PHP 6, the logical progression, or as PHP 7.
In the end PHP 7 prevailed.
What happened to PHP 6?
Those in favor of PHP 7 claim that PHP 6 was the name of a PHP branch that was killed in 2010 and assigning the same name would cause confusion.
PHP 6 was a very ambitious development initiated in February 2005 by a small band of developers from Yahoo, Zend and the core PHP development community. Lack of Unicode support is a big drawback of PHP, and this development aimed at addressing this shortcoming, by introducing Unicode support as standard in all PHP text handling, in PHP engine, extensions, and API. Unicode is a composite industry standard for consistent encoding, representation and handling of text expressed in most writing systems of the world. It provides a unique number for each character regardless of the platform, program or language, thereby simplifying development considerably.
Initially intended as a PHP 5.x version, extensive changes mandated a major version bump and thus the work on PHP 6 was initiated. The project had a good beginning, with a successful proof of concept developed. However, a gross shortage of developers who actually understood the necessary changes and performance issues that arose when conversion was done to and from UTF-16, created big stumbling blocks; to the extent that the project had to be aborted in 2010. Implementation was deemed technically too difficult and a majority of those in the PHP community were wary of converting large chunks of already working code. Some clean-ups and improvements such as traits and closure re-binding, which the Unicode project achieved, were back-ported to PHP 5.4 and life moved on without Unicode support.
The case of PHPNG
In the meantime, Unicode notwithstanding, Facebook wanted certain features in PHP, and tired of waiting for it, decided to go ahead and do it themselves. For instance, the PHP core developers always considered the effort to make the Zend Engine-based PHP fully thread safe as too complicated. But it was not too complicated for the developers at Facebook, who went ahead and made its HHVM-based implementation as thread safe as it should be.
In no time, Facebook’s Hack, an open-source programming language for the HipHop Virtual Machine (HHVM) posed a stiff challenge to conventional PHP. The Hack language provides many features that PHP users want but are not available. Some of these features are:
- Type Hinting: Hack offers support for type hinting on function arguments, function return values, and variables. Type hinting is useful for enforcing type checks, detecting bugs in code and help the HHVM engine generate optimized native machine code. With type hinting, the machine code becomes smaller and faster.
- Asynchronous Programming: Asynchronous programming facilitates execution of multiple tasks in parallel, when waiting for asynchronous tasks that depend on I/O operations such as accessing files, network, and databases. Hack’s await keyword facilitates this.
- Production Ready Standalone Web server: Hack code runs inside HHVM as a single command line script, as a Web server, or as a FastCGI server. This means that HHVM can run PHP Web applications without the need for a separate Web server.
- Multithread server: HHVM runs as a multithreaded Web server, capable of accepting simultaneous connections in separate threads. When PHP tries to do that, it crashes owing to memory corruption caused by multiple threads attempting to access the same data in the same memory space.
PHP developers always put off developing such features, claiming that it would take a lot of time and effort. With Hack in the fray, they no longer had the luxury of such excuses.
To counter the challenge posed by Hack, Dmitry Stogov of Zend launched a quasi-secret development branch of PHP, named PHPNG (PHP Next Generation). PHPNG aimed to infuse PHP with a whole new level of performance and memory usage efficiency.
Apart from the above mentioned Hack features that PHP lacks, PHPNG offered a JIT engine. The JIT engine is capable of compiling Zend opcodes into native machine code dynamically, and would make the code run faster.
PHPNG remains a work in progress, and as such, the full list of proposed features is not yet known, or even defined. However, whatever work done until now seems promising. Server tests clock 20% more requests per second when testing PHPNG with a WordPress installation. However, all PHP applications do not yet benefit from similar performance improvements, and this will not result in speed improvements anyhow.
From PHPNG to PHP 7
The original intention was to merge the PHPNG branch into PHP 6 when complete. However, with PHP 6 being abandoned, it is expected that the PHPNG branch will be merged into PHP 7.
In parallel to the discussion on the naming of the next PHP major version as PHP 6 or PHP 7, a proposal was presented to turn the PHPNG branch as the base of PHP 7. This is most likely to happen, and the new PHP 7 will, in all probability, be a merger of PHPNG to mainstream PHP 5.x version.
Apart from the improvements proposed and intended in PHPNG, such as Asynchronous Programming, JIT engine and more, the new PHP 7 would most likely include the following additional features.
- AST: Abstract Syntax Tree: Nikita Popov, a key person in the PHP community, proposed the implementation of Abstract Syntax Tree (AST), as an intermediary step for the PHP compilation process. An AST offers potential for more optimizations, making PHP run even faster. It also provides scope for launching tools such as static code analyzers to detect bugs or make source level optimizations to the source code.
- Standalone Multi-threading Web Server: It is possible to run PHP from multi-threaded Web servers such as ngynx, lighttpd and Apache in worker mode. However, with its own multi-threading Web server, PHP would be able to handle multiple requests simultaneously, using a single memory pool, and thereby avoid the memory waste that happens when PHP is run in the present FastCGI or in Apache pre-fork mode.
While it is too early to say when PHP 7 would eventually roll out, what is certain is that it is interesting times ahead as PHP is shaken from its lethargy and is trying to catch up with Hack.