Cannot use "yield from" inside a by-reference generator

Description

yield from only emit data by value, not by reference.

Example

<?php

function &foo() {
    yield from [1,2,3];
}

?>

Solutions

  • Remove the reference sign from the function signature.

  • Refactor the code to use yield instead.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.