By Reference, Error Or Notice?

<?php

const A = 1;

function &foo(&$a) {
    return [];
}

$a = 1;
$a = foo($a);
// Notice: Only variable references should be returned by reference

foo(1);
// Fatal error: Uncaught Error: foo(): Argument #1 ($a) cannot be passed by reference

?>

Passing a literal by reference to a method causes a Fatal error, while returning a literal by reference only triggers a Notice. This difference in error level is puzzling, given how similar the operations are. It raises the question: why does one completely halt execution, while the other merely issues a warning and continues running?

See Also

PHP Features

Last updated: 14 July 2026