PHP 5.6 is here!

Posted on: 2014-09-01 | Categories: PHP

PHP 5.6A couple of days ago the PHP Development Team have introduced the new PHP 5.6.0 version. This major release comes with some nice new features, some backward incompatible changes and many improvements. Full list of improvements with details can be found on php.net.

Below i have introduced the main features of PHP 5.6 with examples.

Variadic functions via “…”

This feature with Argument unpacking are my favourites. We don’t need to call func_get_args function any more to get the list of passed parameters. We can use “…” with param name to pass different number of parameters and what is more important they can be combined with “normal” arguments. This works similar to python’s *args.

Sample sum func before:

With PHP 5.6:

This feature is also related to…

Argument unpacking via “…”

We can also pass Arrays and Traversable objects with “…” operator as function argument. This useful feature is called argument unpacking and will not work with assoc arrays.
Example for sending e-mails (with mail function):

Exponentiation via **

In PHP 5.6 has been added support for exponentiation with operator **:

Notice: exponent operator** is RIGHT associative because of:
($a ** $b) ** $c === $a ** ($b * $c)

We can also use shorthand assignment operator: a **=

Importing functions and constants with use operator

With new PHP version we can now import constants and functions – there are no more limitation to classes.

Constant scalar expressions

With new PHP it is also possible to provide a scalar expression for constants.

php://input can be now reused

What does it mean? Before PHP 5.6 after reading data form php://input, we can not use it again. Now it’s possible and php://input is available from various levels of application.

Other features worth noting

  • default character encoding has been set to UTF-8
  • files larger than 2 gigabytes in size are now accepted
  • The __debugInfo() magic method has been added
  • PHP now includes an interactive debugger called phpdbg implemented as a SAPI module
  • GMP objects now support operator overloading and casting to scalar types

Enjoy your new PHP 5.6


This post is also available in: Polish