Returning by reference from a void function is deprecated

Description

The return type void means that no value is returned, not even NULL. This means that the & option has no value here. Since PHP 8.1, this is reported as deprecated.

In the end, it has no value to collect the returned value of a void function, reference or not.

Example

<?php

function &foo() : void { }

?>

Solutions

  • Do not collect the returned valueo of a void function.

  • Remove the reference in the method definition.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See return_reference_on_void.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See return_reference_on_void.

Static Analysis

This error may be tracked down with the following static analysis rules: Functions/NoReferencedVoid.