forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix phpGH-8289: Exceptions thrown within a yielded from iterator are …
…not rethrown into the generator This also fixes the fact that exception traces were not including the generator frame when thrown in a yielded from iterator.
- Loading branch information
Showing
3 changed files
with
110 additions
and
81 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
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,34 @@ | ||
--TEST-- | ||
GH-8289 (Exceptions thrown within a yielded from iterator are not rethrown into the generator) | ||
--FILE-- | ||
<?php | ||
|
||
function yieldFromIteratorGeneratorThrows() { | ||
try { | ||
yield from new class(new ArrayIterator([1, -2])) extends IteratorIterator { | ||
public function key() { | ||
if ($k = parent::key()) { | ||
throw new Exception; | ||
} | ||
return $k; | ||
} | ||
}; | ||
} catch (Exception $e) { | ||
echo "$e\n"; | ||
yield 2; | ||
} | ||
} | ||
|
||
foreach (yieldFromIteratorGeneratorThrows() as $k => $v) { | ||
var_dump($v); | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
int(1) | ||
Exception in %s:%d | ||
Stack trace: | ||
#0 %s(%d): IteratorIterator@anonymous->key() | ||
#1 %s(%d): yieldFromIteratorGeneratorThrows() | ||
#2 {main} | ||
int(2) |
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