PHP 7.3: References in list()

Version7.3
TypeChange

The list() construct is useful to quickly create multiple variables from an array, with array keys being the variable name. Until PHP 7.3, is was not possible to assign the variables by reference. Prior to PHP 7.3, the following snippet would throw a fatal error:

$arr = ['apple', 'orange'];
list($a, &$b) = $arr;
$b = 'banana';
echo $arr[1];
// Fatal error: [] and list() assignments cannot be by reference in .. on line ..

With PHP 7.3, you will be able do so, and the output from echo $arr[1] will be banana. [$a, &$b] = $arr syntax will get this feature too.

You still cannot reference non-referencable variables: list($a, &$b) = [12, 14] will throw:

Fatal error: Cannot assign reference to non referencable value in .. on line ...

Minor nitpick: while "referencable" is an acceptable spelling, "referenceable" is used a lot more widely.

Backwards compatibility impact

None. Instead of using list() assignment to populate multiple variables, I would suggest you to use value objects to make things cleaner. They will be passed by reference anyway and will make your code much cleaner.

RFC Externals.io discussion Implementation