Return Reference On Void¶
There are methods that return void; and methods that return a reference. Until PHP 8.1, they could be the same, although a Notice was emitted. This is now deprecated behavior in PHP 8.1, and shall disappear in PHP 9.
PHP code¶
Before¶
fooPHP Notice: Only variable references should be returned by reference in /codes/return_reference_on_void.php on line 6
Notice: Only variable references should be returned by reference in /codes/return_reference_on_void.php on line 6
After¶
PHP Deprecated: Returning by reference from a void function is deprecated in /codes/return_reference_on_void.php on line 3
Deprecated: Returning by reference from a void function is deprecated in /codes/return_reference_on_void.php on line 3
fooPHP Notice: Only variable references should be returned by reference in /codes/return_reference_on_void.php on line 6
Notice: Only variable references should be returned by reference in /codes/return_reference_on_void.php on line 6
PHP version change¶
This behavior was deprecated in 8.1
This behavior changed in 9.0