-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://bugs.php.net/bug.php?id=64979
- Loading branch information
1 parent
20dbd27
commit f8d8a2d
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
Zend/tests/generators/generator_closure_static_variable.phpt
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,30 @@ | ||
--TEST-- | ||
Closures with static variables can be generators | ||
--FILE-- | ||
<?php | ||
|
||
function new_closure_gen() { | ||
return function() { | ||
static $foo = 0; | ||
yield ++$foo; | ||
}; | ||
} | ||
|
||
$closure1 = new_closure_gen(); | ||
$closure2 = new_closure_gen(); | ||
|
||
$gen1 = $closure1(); | ||
$gen2 = $closure1(); | ||
$gen3 = $closure2(); | ||
|
||
foreach (array($gen1, $gen2, $gen3) as $gen) { | ||
foreach ($gen as $val) { | ||
print "$val\n"; | ||
} | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
int(1) | ||
int(2) | ||
int(1) |