note 118526 added to language.generators.syntax
| From: | HayleyWatson | Date: | Mon, 21 Dec 2015 09:14:35 +0000 |
| Subject: | note 118526 added to language.generators.syntax | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204513@lists.php.net to get a copy of this message | ||
If for some strange reason you need a generator that doesn't yield anything, an empty function
doesn't work; the function needs a yield statement to be recognised as a generator.
<?php
function gndn()
{
}
foreach(gndn() as $it)
{
echo 'FNORD';
}
?>
But it's enough to have the yield syntactically present even if it's not reachable:
<?php
function gndn()
{
if(false) { yield; }
}
foreach(gndn() as $it)
{
echo 'FNORD';
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 122.57.151.138
----
Manual Page -- http://php.net/manual/en/language.generators.syntax.php
Edit -- https://master.php.net/note/edit/118526
Del: integrated -- https://master.php.net/note/delete/118526/integrated
Del: useless -- https://master.php.net/note/delete/118526/useless
Del: bad code -- https://master.php.net/note/delete/118526/bad+code
Del: spam -- https://master.php.net/note/delete/118526/spam
Del: non-english -- https://master.php.net/note/delete/118526/non-english
Del: in docs -- https://master.php.net/note/delete/118526/in+docs
Del: other reasons-- https://master.php.net/note/delete/118526
Reject -- https://master.php.net/note/reject/118526
Search -- https://master.php.net/manage/user-notes.php