What is new in php 5.6. Variadic functions and namespaced functions

The next major php release is 5.6. Here are two new abilities already accepted by php community to be included into language from version 5.6.

1. Variadic functions

func_get_args() is not needed any more!

The ...$params syntax indicates that this is a variadic function and that all arguments after $query should be put into the $params array.

By reference

Type hint


Summary. The feature adds the following new syntax:

  • function fn($arg, ...$args): Capture all variadic arguments into the $args array
  • function fn($arg, &...$args): Do the capture by reference
  • function fn($arg, array ...$args): Enforce that all variadic arguments are arrays (or some other typehint)
  • function fn($arg, array &...$args): Combine both – variadic arguments are arrays that are captured by-reference

2. Importing namespaced functions

This is the new ability to import functions into a namespace. This feature introduces a new keyword combination use function. It works as follows:

All of this applies also to namespaced constants. For consistency, a use const sequence is introduced:

Just like classes, it is possible to alias imported functions and constants: