|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-02-12 15:39 UTC] requinix@php.net
-Status: Open
+Status: Feedback
[2021-02-12 15:39 UTC] requinix@php.net
[2021-02-12 17:38 UTC] petr dot vejchoda at seznam dot cz
-Status: Feedback
+Status: Open
[2021-02-12 17:38 UTC] petr dot vejchoda at seznam dot cz
[2021-02-12 18:27 UTC] petr dot vejchoda at seznam dot cz
[2021-02-12 18:39 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2021-02-12 18:39 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 20 14:00:02 2025 UTC |
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.