Re: Needs Feedback - Yield without value in reference generator function does not create notice

From: Date: Tue, 26 Nov 2024 11:59:27 +0000
Subject: Re: Needs Feedback - Yield without value in reference generator function does not create notice
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 26.11.2024 at 12:31, Claude Pache wrote:

>> Le 26 nov. 2024 à 01:49, aggelos bellos <[email protected]> a écrit :
>>
>> In this issue #16761 <https://github.com/php/php-src/issues/16761>
>> it was verified that in the above code it should throw a notice for both yields:
>> ```
>> <?php
>> error_reporting(E_ALL);
>> function &y()
>> {
>>   yield null; // warning
>>   yield; // no warning, agreed to be a bug
>> }
>> foreach (y() as &$y);
>> ```
>> I have created this PR <https://github.com/php/php-src/pull/16882>
>> which adds the "missing" notice but we aren't sure on
>> how to continue on this.
>> There are 2 main questions:
>> Should we continue with adding the missing notice and merge it also in master?
>> Should we deprecate / remove the usage of yield without value in reference generator
>> functions?
>
> A notice would be consistent with what happens with: function &f() { return; };
> f();. But don’t add new notices in patch releases, otherwise you may break without warning
> a non-trivial amount of code that conflates notices with fatal errors. The bug is not serious enough
> to warrant such a risk.
>
> Whether it should be deprecated, is a separate question. You should also consider what to do
> with:  function &g() { yield null; }, function &g() { if (false) yield;
> }, function &f() { return; }, etc.

In my opinion, whether it should be deprecated is not a separate
question, but the one we should answer first.  If we're not going to
deprecate/remove the auto-conversion to a reference, we may as well drop
the notice altogether, instead of adding a further notice.

Christoph


Thread (4 messages)

« previous php.internals (#126058) next »