The most exciting events in 2015 in the PHP world was the release of PHP 7, 10 years on from the release of the last major version, PHP 5. Together with a major step forwards, PHP 7 introduces plenty of recent features and performance upgrades.
However, it also removes old, deprecated features, which introduces some suitability breaks, making it harder for older applications to move to the new version. This guide should serve as a quick tour on what to anticipate if you plan on moving your existing applications, or building new ones, on top of PHP 7.
But Wait, Where Did PHP 6 Go?
In case you have not been working with PHP lately, you might question what happened to PHP 6, why the skip from PHP 5 to PHP 7? Well, long history short, PHP 6 was a failure. The main feature of version 6 was native support for Unicode characters since PHP is employed mainly in web development and the web needs Unicode, so the move to bring Unicode to PHP made sense.
The idea was to bring complete support for Unicode to the core itself. It would have brought extended functions to the language, from the ability to use ridiculous emojis as variable and function names, to powerful international string functionality. Regarding instance, when another terminology uses upper and lower case letters differently from English, or when a name in Chinese figures needs to be changed to English.
Unfortunately, this ambitious plan proved to be a greater problem than anticipated. Much of the codebase got to be ported to back up Unicode for both key and important extensions, which proved tedious and challenging. This slowed down development of other features in the language, frustrating many PHP developers in the process. Extra hurdles showed up, which resulted in less interest in having a native Unicode support, eventually leading to the project being left behind.
Since resources, such as books and articles, got been written for PHP 6 and its Unicode support, the new version would be renamed PHP 7 to avoid confusion.
Anyway, enough dwelling in the sad past, let’s see what PHP several produces in the party.
Overall performance Battle, PHP 7 compared to. PHP 5
With practically all updates, minor performance upgrades are to be expected. However, this time around PHP brings a significant development over earlier versions making sheer performance one of PHP 7’s most attractive features. This comes as part of the “PHPNG” project, which tackles the internals of the Zend Engine itself.
By refactoring internal data structures and adding an intermediate step to code compilation as an Abstract Syntax Shrub (AST), the result is superior performance and more efficient memory allocation. The particular numbers themselves look very promising; benchmarks done on real world programs show that PHP 7 is twice as fast as PHP 5. 6 on average, and results in 50 percent less memory consumption during requests, making PHP 7 a strong rival for Facebook’s HHVM JIT compiler. Have a look at this infographic from Zend depicting performance for some common CMS and Frameworks.
PHP several Syntactic Sugar
PHP several comes with new syntax features. Whilst not extending the features of the language itself, they provide a much better, or easier, way of producing your code more enjoyable to create and pleasing to the eye.
Null Coalescing Operator
This solves a common problem in PHP programming, where we want to assign a value to a variable from another variable, if the latter is actually set, or otherwise provide a different value because of it. It’s commonly used when we work with user-provided insight.
New Features In PHP 7
But of course PHP 7 also brings new and exciting efficiency with it.
Scalar Parameter Varieties & Return Type Tips
PHP 7 extends the previous type declarations of parameters in methods ( classes, interfaces and arrays) by adding the four scalar types; Integers (int), floats (float), booleans (bool) and strings (string) as you possibly can parameter types.