Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When no key is explicitely yielded PHP will used auto-incrementing keys as a fallback. They behave the same as with arrays, i.e. the key is the successor of the largest previously used integer key.
- Loading branch information
Showing
5 changed files
with
313 additions
and
78 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,22 @@ | ||
--TEST-- | ||
Generator keys are auto-incrementing by default | ||
--FILE-- | ||
<?php | ||
|
||
function *gen() { | ||
yield 'foo'; | ||
yield 'bar'; | ||
yield 5 => 'rab'; | ||
yield 'oof'; | ||
} | ||
|
||
foreach (gen() as $k => $v) { | ||
echo $k, ' => ', $v, "\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
0 => foo | ||
1 => bar | ||
5 => rab | ||
6 => oof |
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
Oops, something went wrong.