Define Variable By Reference
<?php
function foo($a) {}
// 2 * undefined variable
foo($b);
var_dump($b); // NULL
// no error
function foo2(&$a) {}
// undefined variable
foo($c);
// Now, $c exists
var_dump($c); // NULL
Assigning a value is not the only way to assign a variable in PHP: passing an undefined variable to a method, with a reference, creates automatically that variable. When it is not set inside the method, it still is valued null in the calling context.
In the end, the main difference is only one warning is emitted, instead of two.
See Also
- Now you see me [Try me]
PHP Error Messages
PHP Features
Last updated: 09 November 2026