Skip to content

PHP does not report an error when using unexpected & inside reference generator function #16679

@ohyeaah

Description

@ohyeaah

Description

The following code:

<?php
error_reporting(E_ALL);

function &moh()
{
  $test = 5;
  yield &$test;
}

foreach (moh() as &$value)
  var_dump($value);

Resulted in this output:

NULL

But I expected this output instead:

PHP Parse error:  syntax error, unexpected token "&" in /home/user1/test.php on line 7

PHP Version

PHP 8.2.24

Operating System

Debian GNU/Linux 12 (bookworm)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions