PHP 5.6.0 Adds Constant Scalar Expressions, Variadic Functions and Improvements

PHP 5.6.0 has been released with support for constant scalar expressions, variadic functions in addition to argument unpacking using the … operator. The latest release also provides support for exponentiation using ** operator and phpdbg.

PHP 5.6.0

Constant Scalar Expressions

const ONE = 1;
const TWO = ONE * 2;
class C {
    const THREE = TWO + 1;
    const ONE_THIRD = ONE / self::THREE;
    const SENTENCE = 'The value of THREE is '.self::THREE;
    public function f($a = ONE + self::THREE) {
        return $a;
echo (new C)->f()."\n";

Variadic functions

function f($req, $opt = null, ...$params) {
    // $params is an array containing the remaining arguments.
    printf('$req: %d; $opt: %d; number of params: %d'."\n",
           $req, $opt, count($params));
f(1, 2);
f(1, 2, 3);
f(1, 2, 3, 4);
f(1, 2, 3, 4, 5);

Argument unpacking

function add($a, $b, $c) {
    return $a + $b + $c;
$operators = [2, 3];
echo add(1, ...$operators);

Exponentiation via **

printf("2 ** 3 ==      %d\n", 2 ** 3);
printf("2 ** 3 ** 2 == %d\n", 2 ** 3 ** 2);
$a = 2;
$a **= 3;
printf("a ==           %d\n", $a);

With the help of 5.6.0, you will be able to make use of ‘use’ keyword to import function and constant. You can also use phpdbg as an interactive integrated debugger SAPI.

PHP 5.6.0 include support for operator overloading in GMP objects and file uploading larger than 2 GB. You should also note that php://input is now reusable and $HTTP_RAW_POST_DATA is deprecated.

PHP 5.6.0 also includes new functions such as hash_equals(), which enables you to easily compare two strings in constant time. It also includes _debugInfo() function that allow obkects to change the properties and values that are shown when the object is output using var_dump().

Some of the other new features and improvements included with PHP 5.6.0 are as follows

  • gost-crypto hash algorithm
  • SSL/TLS improvements
  • pgsql async support
  • Array keys won’t be overwritten when defining an array as a property of a class via an array literal
  • json_decode() is more strict in JSON syntax parsing
  • Stream wrappers now verify peer certificates and host names by default when using SSL/TLS
  • GMP resources are now objects
  • Mcrypt functions now require valid keys and IVs

PHP 5.6.0 Migration Guide provides detailed list of all features along with associated source code and its output.

Leave a Comment