The development of PHP is from 5.6 to 8.0

Tram Ho

A condensed review of changes in PHP v7.x in under 15 minutes

When PHP 7.3 was released, I decided to look into PHP development in detail: what is being developed and which direction to better understand the new potential and optimization of the widely popular programming language. this.

After searching for a condensed list of features that PHP implemented during PHP v7.x development, I decided to compile this list myself – in a way that catches up with the technology that I believe in. That may also find it useful.

We will start with PHP 5.6 as a baseline and will look at what has been added and changed. I have also added links to the official document for each one mentioned, so if you are interested in reading further – feel free.

PHP 7.0

Anonymous Class Support

An anonymous class can be used on a named class:

  • When the class does not need to be recorded.
  • When the class is only used once during execution.

 

Integer division function – a safe way to divide (even by 0). It returns the integer division of the first operand by the second operand. If the divisor (second operand) is zero, it will throw E_WARNING and return FALSE .

 

Added a new null merge operator – is ??

 

Added new space ship operator (<=>)

Used to optimize and simplify comparisons.

 

Declare type declaration

This is just the first step to achieving a more powerful programming language in PHP – v0.5.

 

Declare type declaration

Added the ability to return types other than scalar – classes including inheritance. Still somehow completely missed the ability to make it optional (introduced in v7.1.

 

Declare by group

Generator Delegation

The following new syntax is allowed in the body of generator functions:

 

Improve the performance

PHP7 is twice as fast as PHP5.6

 

Memory usage is significantly reduced

As you can see from the diagrams, PHP 7.0 is a major improvement in performance and memory usage . For pages with database queries, version 7.0.0 is 3 times faster than 5.6 with opcache enabled and 2.7 times faster without opcache ! In terms of memory usage, the difference is also very significant!

 

Throwable interface

Reconstructing exception classes to have a non-intuitive naming scheme that will lead to less confusion, especially for newer users.

Errors and Exception are now implemented Throwable

This is the hierarchy of Throwable

Note: You can only implement Throwable through Error and Exception .

 

Unicode Codepoint Escape Syntax – ” u {xxxxx}”

Context Sensitive Lexer

With the words globally reserved has now become semi-reserved:

Generator return expressions

Syntax variable uniformity

Support level for functions dirname ()

PHP 7.1

Nullable Types

 

Void Returns

Unlike other return types that are executed when the function is called, this type is checked at compile time, which means that an error is generated without calling the function.

A function return type is void or function void , can be returned underground or return statement with no value:

 

Iterable pseudo type

Typically, a function accepts or returns an array or object Implementing a Traversable be used with foreach . However, since arrays are primitive and Traversable is an interface, there is currently no way to use type declarations on parameters or return types to indicate that the value is repeatable.

iterable can also be used as a return type to indicate a function will return a repeating value. If the returned value is not an array or instance of Traversable , TypeError will be thrown.

Parameters declared with iterable can use null or an array as the default value.

 

Closure from callable

 

The square bracket syntax allows destructuring assignment arrays

Syntax square brackets for list list ()

 

Class constant visibility

Catching Multiple Exception Types

PHP 7.2

Extend the parameter type

 

Counting uncountable objects

Calling count() on a scalar or object without implementing the Countable interface returns 1 (illogical).

In this version, we added a warning when calling count() with a scalar, null parameter or an object that does not implement Countable .

 

The comma syntax is used in the namespace

 

Argon2 Password Hash

The existing password_ * functions provide a simple interface to hash passwords. This RFC recommends deploying Argon2i (v1.3) in password_ * functions to use a safe alternative to bcrypt .

 

Debugging PDO Prepared Statement Emulation

PHP 7.4 (In development)

Typed properties

 

Foreign Function Interface

FFI is one of the features that makes Python and LuaJIT very useful for rapid prototyping. It allows to call C functions and use C data types from pure scripting languages ​​and thus develop more efficient “system code”. For PHP, FFI opens a way to write PHP extensions and constraints into C libraries in plain PHP.

 

Null Coalescing Assignment Operator

 

Preloading

PHP has been using opcode caches for a long time (APC, Turck MMCache, Zend OpCache). They achieve significant performance gains by NEARING eliminating the overhead of recompiling PHP code. Preloading will be controlled only by a new php.iniopcache.preload . Using this directive, we will specify a PHP file – which will perform the preloading task. Once downloaded, the file is then fully executed – and can be preloaded with other files, either by them or by using the opcache_compile_file() function.

 

Hash extention is always available

This will make the hash extension (ext / hash) available, similar to date. The hash extension provides a very rich utility with many extremely useful hashing algorithms in modern applications, not only in user code but also very much internally.

On the way to PHP 8.0

JIT.

Briefly. When you launch a PHP program, Zend Engine will parse the code into an abstract syntax tree (AST) and translate it into opcodes. Opcodes are executable units for the Zend Virtual Machine (Zend VM) . Opcode is quite a low level, so translating the code to your computer is much faster than the original PHP code. PHP has an OPcache extension in the core, to store these opcodes.

“JIT” is a technique that will compile parts of the code at runtime, so that the compiled version can be used instead.

 

This is one of the last and greatest PHP optimization strategies still on the table. PHP engineers are looking to see if this new approach can surpass their applications. Really interested in this.

 

Consistently type errors for internal functions

Make the internal parameter analysis APIs always generate TypeError if parameter parsing fails. It should be noted that this also includes ArgumentCountError (child of TypeError ) for cases where too few / many arguments are passed.

Compare performance

I have written a simple test to help easily compare the performance of different PHP versions (using Docker). This will even allow you to easily test the performance of new PHP versions just by adding new container names.

Running on Macbook pro, 2.5 GHz Intel Core i7.

If you want to test yourself, you can find the source code in this repository .

Benchmarks from PHP 5.6 and above

I really like the visual performance summary from servbolt.com of all major versions from 5.6 and up. See results in the tables below.

Performance summary

PHP 7.0.0 is a milestone with significantly improved performance and lower memory usage but PHP maintainers are simply out of ideas to improve it. One of the remaining points is to compile JIT (Just in time). And it comes with PHP 8.0.

Development

Throughout PHP 7.x versions, there is a more visible (and a bit more objective) path and a modern programming language. However, PHP prefers to apply useful and neat features from other programming languages.

We’ll see some of the better features soon, like:

With these, PHP developers will join a group of modern language applicators. No language is perfect, but PHP is paving the way for the future.

TL; DR

To further shorten, I have chosen most of the important changes to my personal opinion with the latest version of PHP 7.3. There they are:

 

References:

https://wiki.php.net/rfc https://www.cloudways.com/blog/php-5-6-vs-php-7-symfony-benchmarks/ https://servebolt.com/articles/wordpress -5-0-php-7-2-vs-php-7-3-performance-and-speed-benchmark /

The head illustration was made by Badoo team for Badoo Tech blog

https://tech.badoo.com/ru/article/511/php-8-chego-zhdat-pismo/

Source: https://medium.com/@meskis/evolution-of-php-v5-6-to-v8-0-c3514ebb7f28

Share the news now

Source : Viblo