PHP 7 – 5 things you need to know

PHP 7 candidate has been released and it has some cool improvements to show! Some argue that there wasn’t a need to release it currently as most of the improvements it provides were already quite possible through various ways in previous versions too.

Lets see some of the things about PHP 7 and how it promises to improve our lives as webdeveloper or owner of websites.

1. Why is it PHP 7 and not PHP 6

PHP 6 was a separate project earlierĀ but it never made to surface. So in order to avoid the confusion among people if it’s the final version of the same package or is it a new one, the new package was named PHP 7.

So just because the PHP 6 wasn’t released, it doesn’t mean that the name should follow the convention of naming in sequence, or should it?

By the way, microsoft windows also skipped the windows 9 and jumped to 10!

2. PHP#NG (Latest zend engine for PHP 7)

Zend engine has been out there since 1999 and is powering PHP based sites from PHP 4 onwards.

Note that zend engine is different from zend framework which is an open-source C based interpreter for PHP language.

Currently, PHP 5.x uses an older zend engine II which adds extensible object model resulting in quite enhanced performance to the PHP 5.x websites.

However, the latest version of end engine (PHP#NG -> PHP next generation) is an update with PHP 7 and results in huge improvement in the language performance.

3. Twice as fast as previous versions

PHP 7 is almost twice as fast as the previous version. This is possible due to changes including the PHPNG (zend engine) that optimized memory usage remarkably and includes JIT (just-in-time) compilation that allows compilation to be done in run time instead of being done prior to the execution of code.

The speed difference can be seen through benchmark tests comparing PHP7 with previous technologies for WordPress versions 3.6 and 4.1 in the image below.

wordpress speed php7

It can be seen that it’s a huge improvement from the PHP 5.6 version and is comparable to HHVM.

4. New operators: Spaceship and Null Coalescing

PHP 7 introduces new operators: Spaceship and Null Coalescing.

Spaceship operator <=> is also called three-way comparison operator. It returns -1 if left is smaller, 0 if both are equal and 1 if right is smaller.

Null Coalescing operator ?? is used to check if something exists and if not then return a default value.

Now both of these are a great improvement none the less, but mostly, these tasks can be done without these operators too, but not in all conditions probably?

5. Add anonymous classes

PHP 7 allows the programmers to add anonymous class in their code like many other languages including C# and Java do.

An anonymous class is a class without a name, however the object that it instantiates has the same functionality as the objects instantiated by the class with a name.

Its syntax is similar to the traditional PHP classes too, just the name is missing.

Anonymous classes can speed up coding and execution, both. However they work best when they’re only used once in the execution and also in the cases when the class documentation isn’t needed.

These are just the tips of the iceberg. There are numerous changes and improvements in the new version of PHP.

Definitely there are going to be bugs too, but that’s the part of development! Happy coding!

 

Leave a Reply

Your email address will not be published.