forked from php/php-src
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If the generator is used as a coroutine it often doesn't make sense to yield anything. In this case one can simply receive values using $value = yield; The yield here will simply yield NULL.
- Loading branch information
Showing
5 changed files
with
127 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--TEST-- | ||
yield can be used without a value | ||
--FILE-- | ||
<?php | ||
|
||
function *recv() { | ||
while (true) { | ||
var_dump(yield); | ||
} | ||
} | ||
|
||
$reciever = recv(); | ||
var_dump($reciever->current()); | ||
$reciever->send(1); | ||
var_dump($reciever->current()); | ||
$reciever->send(2); | ||
var_dump($reciever->current()); | ||
$reciever->send(3); | ||
|
||
?> | ||
--EXPECT-- | ||
NULL | ||
int(1) | ||
NULL | ||
int(2) | ||
NULL | ||
int(3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters