TechTip: PHP 7.0 Is Coming, Part 1

Web Languages
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

PHP 7.0 is in the process of coming to you now, probably before the end of the year. But why should you care? What does it offer? And when will it be available?


Sometime between now and the end of 2015, a new version of PHP, PHP 7, will hit the streets. Currently, most of us are using 5.3 or 5.4, and I'm guessing that many of you are wondering what happened to PHP 6. Did they just skip it, or is there something in the way PHP handles cardinal numbers to cause the jump?


The truth is, PHP 6 is out there, but not many people have chosen to use it. Why not? PHP 6 was the release that was going to provide Unicode support for PHP, incorporating the International Components of Unicode (ICU) library into PHP and representing all strings in a UTF-16 format. While this was a nice idea, it required some additional steps during processing as everything had to be taken from the encoding format it was in, converted to UTF-16, and then converted back again. Plus UTF-16 strings take up twice as much space as UTF-8.


There wasn't much of a performance gain, so many people opted not to go that direction. Work on the release stalled, and when 5.3 was released in 2009 with many of the non-Unicode features from 6, that sort of put the nail in the coffin. Work on 6 formally stopped in 2010, and 5.4, with still more 6.0-oriented non-Unicode features, followed shortly after.


When it came time to look toward the next big release of PHP, the consensus was to let 6 rest in peace and move on to 7 as the flagship number.


How Does a New Version of PHP Develop?

Those of us in the RPG world are used to new versions of the language coming out because the software vendor that "owns" the language (IBM, in our case) decides that there's a need for new functionality. True, they take input from the user community, but in the end they develop the list and do the work required to create the new functions. Plus, in the RPG case, there's a stated policy that nothing is ever taken out of the language, so you can upgrade to a new version and not have to worry about your stuff breaking. Yes, some functions were lost when we went to /Free, but you can still use them in procedural code specs, so they're not really deprecated.


But PHP is open source. Zend kind of shepherds it along, but there are other versions of it out there, such as the one Facebook has.


Anyone can propose an idea for incorporation into a new release, although that's usually done only by some of the top developers. It's assumed that you'll not only propose the issue, but specify, in very great detail, how it would be approached and then eventually do the work on it. Anyway, you do this by setting up a Request for Comments (RFC) on the PHP Wiki. The RFC is left open for at least two weeks but often for longer while people review and comment on the proposed change. Then a vote is called for by the author whenever the discussion seems to have run its course. Things that receive a majority vote are then approved for incorporation into the next release.


Because things are brought up and voted on individually, the process may string along for awhile and not everything is released simultaneously. The first version of PHP 7, which will contain some but not all of the functional enhancements, will be out probably in June, but that's pretty much just for hard-core developers. It certainly will not be available to everyone. Why not? Because it's not like a new version of a browser, where you download IE15 and suddenly you have all the capabilities. PHP is a server-side language, so you don't really have access to the language except through the "stack" in your server environment. Real developers tend to "roll their own." That is, they have all of the software for the PHP stack loaded on their PC, so they can download the new version of the language and be ready to go. More-normal people have access to a copy of Zend Server or else use MAMP/WAMP/LAMP on their PCs. So PHP 7 will not really be available to them until it's incorporated into those products.


The full version of the software will probably not be out till close to the end of the year. And when that happens, what will we see? Ah, that's the question now, isn't it?


So What Is PHP 7 All About?

We are used to the first release of a new flagship number being a big one, something that dramatically extends the language or takes it in a new direction, such as PHP 3 adding OO functionality. So what's the focus in 7?


Certainly there are functionality improvements: the introduction of strict typing, the Space Ship Operator (<=> ) so named because it sort of looks like a Star Wars TIE Fighter, and many others. Plus, it does fix some past inconsistencies that are sitting out there.


But probably the biggest story is performance. PHP 7 is dramatically faster than previous versions, probably twice as fast as 5.6, according to available benchmarks. Apps will not only run faster but, because they do, they will require less server power, which means less electricity, making 7 a very green web language. There are a ton of bench marks out there on the web comparing 7 to HHVM, but the examples Zend provides show how superior 7 is to the current 5.6. Up to this point, the performance leader in the PHP world was Facebook's version of HHVM, but 7 seems to be able to beat even that.


How has PHP gotten this performance boost? Well the first ingredient is PHPNG. This is a refactored version of the existing Zend Engine, the thing that makes PHP run. With PHP 7, PHPNG is now the main engine, replacing the old core. What's different between PHPNG and the old engine is the way that PHPNG handles data, particularly data structures, doing so more efficiently and using less storage. For example, the new engine now differentiates between native data types, like integers, and more complex types, like arrays. By not having native data types go through all the manipulations that complex types go through, PHPNG saves a great many instructions as well as storage. Plus, even the way complex types are handled is much more efficient. For example, hash tables upon which arrays (which are very important in PHP) are based are now handled in a very C-like manner (remember, under the covers, PHP is written in C) rather than the way most dynamic languages do. The result is a tremendous savings in processing power and storage required to handle a given app.


The other thing that has happened is the addition of an Abstract Syntax Tree (AST) structure to the "compile" process. The AST is a tree structure representation of the script, which consists of nodes that represent the various functions within the script. As the tree is built, additional annotation information can be added to it to separate the parsing of the script from the implementation of the code. In essence, it separates the code syntax from the parsing process so that many of the syntax-related rules that are now required in 5.4 will not be needed, resulting in a simpler, more-consistent syntax structure.


As an aside, Facebook's HHVM uses a JIT precompiler to provide its performance boost, and Zend looked at that as they went through this process. In the end, Zend decided that, while this did improve the benchmark, it had relatively little impact on the running of actual applications. As a result, no JIT precompiler will be used, but ongoing improvements in PHPNG should continue to net performance gains.


But There's More…Next Month

There's more to PHP 7 than lightning speed. There's also a series of functionality improvements that we shall go into in the next exciting installment. Stay tuned.