php / php/php-src

yield without value in reference generator function does not create notice

Open
#16,761 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Category: Generators Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php
error_reporting(E_ALL);
function &y()
{
  yield null; // warning
  yield; // no warning
}
foreach (y() as &$y);

Resulted in this output:

PHP Notice:  Only variable references should be yielded by reference in /home/user10/test.php on line 5

But I expected this output instead:

PHP Notice:  Only variable references should be yielded by reference in /home/user10/test.php on line 5
PHP Notice:  Only variable references should be yielded by reference in /home/user10/test.php on line 6
PHP Version

PHP 8.2.24 (cli) (built: Sep 27 2024 04:16:10) (NTS)

Operating System

Debian GNU/Linux 12 (bookworm)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reference generator example on PHP 8.2.24 with E_ALL enabled, then trace how the two yield forms are handled. Done means the value-less yield emits the same notice as yield null, with regression coverage for both lines.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.