Req #80735 [NEW]: yield break
From: petr dot vejchoda at seznam dot cz
Operating system: Win10
PHP version: 7.4.15
Package: Unknown/Other Function
Bug Type: Feature/Change Request
Bug description:yield break
Description:
------------
I was looking for a way to end a end a generator prematurely without
necessity to make it to the end of function/method. Also way of marking
a function/method as an empty generator. And I found none. If there is
one, one can say I can't google properly, or one could also say it was
not written in the documentation.
Test script:
---------------
abstract class Base
{
__construct()
{
foreach($this->generator() as $key => $value)
{
$this->doSomething($key, $value);
}
}
protected abstract function generator(): traversable;
}
class Child extends Base
{
// empty generator??
protected function generator()
{
if (false)
{
yield null;
}
}
}
Expected result:
----------------
I would appreciate some language construct like yield break; that would
end the generator prematurely, or could be used to simplify empty
generator syntax.
yield from new EmptyIterator(); is not really an option for me, sorry,
thats just plain ugly.
--
Edit bug report at https://bugs.php.net/bug.php?id=80735&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80735&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80735&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80735&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80735&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80735&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80735&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80735&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80735&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80735&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80735&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80735&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80735&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80735&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80735&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80735&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80735&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80735&r=mysqlcfg
Thread (5 messages)
- petr dot vejchoda at seznam dot cz