What’s New in PHP 7: Things You Should Know

If you are a developer, you probably know the feature-complete beta version of the new PHP 7 is out. The 7.0.0 version contains many cool features and functionalities. However, we recommend you to not use it in production environment, until you get the stable version, which is expected in November ’15.

You are free to test and play with the latest beta version, and report bugs if you discover during the testing. We are listing all changes/up-gradation that you’ll see in PHP 7.0.0.

16. This is PHP 7 (not 6)

PHP version 7

The current stable version is PHP 5.6. So, many developers are expecting 6.0 version. What they don’t know is, PHP 6 already existed in the past as an experimental process, but never reached to the production phase. The core development team decided they would pass the PHP 6 name for the next major release.

15. 64-Bit Windows Support

64-bit support

The current PHP version doesn’t provide 64 bit integer or large file support. The things are going to change in the future, as PHP 7 introduces consistent 64-bit support, that means both native 64-bit integers and large file will be supported.

14. Removal of Deprecated Functions and Extensions

Removal of Deprecated Functions and Extensions

One of the main goals of PHP 7 was to free up the memory to enable improvement, so it became necessary to eliminate old unsupported server APIs, extensions and deprecated functionalities.
All removed items haven’t been used for a long time. However, if you have a legacy application running on older versions, upgrading to PHP 7 can potentially break the code.

Read: 30 Bug Tracking Tools For Developers

13. Group Use Declarations

Group Use Declarations

This RFC is created to improve current PHP namespace implementation by introducing the concept of group of declaration. This feature is useful for those coders who usually import many classes from the same namespace. The new syntax eliminates verbosity, makes your code tidier and saves you a lot of typing time.

12. Anonymous Classes

Anonymous Classes

The concept of anonymous classes is already being used in other object-oriented programming languages like Java and C#. They are nothing but a class without a name that can speed up coding as well as execution time. You should use them when a class is used only once during execution and when a class need not to be documented.

11. Uniform Variable Syntax

Uniform Variable Syntax

Uniform variable syntax solves many inconsistencies in how expressions are evaluated. For instance, the ability to call closure assigned to properties using ($object->closureProperties)(), as well as being able to chain static calls.

In older version of PHP, $obj->$properties[‘name’] would access the property whose name is in the name key of properties array. Now, it would access the name key of the property whose name resides in $properties.

10. Unicode Codepoint Escape Syntax

Unicode Codepoint Escape Syntax

The new escape character (\u) lets us specify Unicode character code points (in hexadecimal) unambiguously inside strings. For example, if you are unable to type any emoji, you can use its escape sequence instead.

9. Shared Parent Class in Exception Handling

Shared Parent Class in Exception Handling

For PHP coders, handling fatal and catchable fatal errors has never been an easy task. With new Engine Exceptions, you can replace these kinds of errors with exceptions.
To enable coders to catch both traditional exception and engine exception, PHP 7 introduces a new shared parent class under the name of \BaseException.

8. Bind Closure on Call

Bind Closure on Call

Closure::bind() and Closure->bindTo() allows you to change the binding of $this and the calling scope, separately or together, creating a duplicate closure. In PHP 7, there is an easy way to do this at call time, by binding both $this and calling scope to the same object with the addition of Closure->call(). The method takes the object as its first argument, followed by any argument to pass into the closure.

7. Null Coalesce Operator

Null Coalesce Operator

Coalesce operator is denoted by “??”. It returns the result of its first operand if it exists and is not NULL, otherwise, it will return second operand. That means it is completely safe to use coalesce as it will not raise an E_NOTICE even if the value does not exist.

6. Combined Comparison Operator

Combined Comparison Operator

Combined comparison operator (also known as spaceship operator) is similar to version_compare() or strcmp() in behavior, but it can be used in all generic PHP values. It already exists in Ruby and Perl programming language.
The operator returns -1 if the left operand is greater, 0 if both are equal and 1 if the left is greater.

5. Generator Return Expression and Generator Delegation


The generator return expression allows you to return a value upon successful completion of a generator. In PHP 7, you can call $generator->getReturn() to retrieve the return value. If the generator has not yet returned or thrown an uncaught exception, $generator->getReturn() will throw an exception. In case, if generator has completed but there was no return, NULL is returned.

generator delegation

The generator delegation feature allows you to return another iterable structure that can itself be traversed, whether it’s an iterator, array, or another generator. The iteration of the substructure is done by the outermost original loop, rather than a recursive one.

4. Return Type Declarations

Return Type Declarations

Many programmers would like to declare the return type of a function. It helps to prevent unintended return values and sub-types from breaking the expected return type of the super-type, especially in interfaces. Moreover, PHP 7 comes with 4 new type decelerations for scalar type – string, int, float and bool. These new types allow coders to specify that they are expecting integer, float, string and boolean to be returned.
In the above image, the function foo is supposed to return in array. Checkout some complex examples.

3. Abstract Syntax Tree

The largest and most invisible change is the addition of an Abstract syntax tree – an intermediate representation of the code during compilation. It replaces the existing practice of emitting opcodes directly from the parser. This allows us to remove a number of hacks and makes the implementation more understandable and maintainable. Also, you can implement syntax that was not feasible with single pass compilation process.

2. The All New Zend Engine

Zend Engine

The first Zend Engine introduced in 1999 in PHP 4. It is an open source scripting engine (written in C) that interprets PHP.  The current PHP version uses Zend Engine II, which provides memory and resource management and adds an extensible object model and significant performance enhancement to the language.
The new Zend Engine III, originally codenamed phpng, is in development for PHP 7.

1. Performance + Memory Saving

PHP performance

The biggest reason for upgrading to PHP 7 is its performance. This is good news, especially for smaller hosts, as they will be able to host more customers on the same hardware. The performance of the 7th version is on par with Facebook HHVM, which features JIT (just-in-time) compiler that allows compilation at run time rather than prior to execution. There is also substantial memory saving, as optimization of internal data structures.

Recommended: 30 Amazing PHP Libraries for Programmers and Developers

As you can see in the graph released by Zend, WordPress request on PHP 5.6 executes under 100M CPU instructions, while PHP 7 only executes 25M to do the same job. Moreover, testing shows that you can run 3x Magento transactions on the same hardware, and Drupal 8 runs 72% faster with PHP 7.

Written by
Varun Kumar

I am a professional technology and business research analyst with more than a decade of experience in the field. My main areas of expertise include software technologies, business strategies, competitive analysis, and staying up-to-date with market trends.

I hold a Master's degree in computer science from GGSIPU University. If you'd like to learn more about my latest projects and insights, please don't hesitate to reach out to me via email at [email protected].

View all articles
Leave a reply

  • Blogging Master says:

    Good information and not even known it.

  • leitecarvalho says:

    in #7, both the first and 3rd example are the same model, right?