gh8289.phpt 672 B

12345678910111213141516171819202122232425262728293031323334
  1. --TEST--
  2. GH-8289 (Exceptions thrown within a yielded from iterator are not rethrown into the generator)
  3. --FILE--
  4. <?php
  5. function yieldFromIteratorGeneratorThrows() {
  6. try {
  7. yield from new class(new ArrayIterator([1, -2])) extends IteratorIterator {
  8. public function key(): mixed {
  9. if ($k = parent::key()) {
  10. throw new Exception;
  11. }
  12. return $k;
  13. }
  14. };
  15. } catch (Exception $e) {
  16. echo "$e\n";
  17. yield 2;
  18. }
  19. }
  20. foreach (yieldFromIteratorGeneratorThrows() as $k => $v) {
  21. var_dump($v);
  22. }
  23. ?>
  24. --EXPECTF--
  25. int(1)
  26. Exception in %s:%d
  27. Stack trace:
  28. #0 %s(%d): IteratorIterator@anonymous->key()
  29. #1 %s(%d): yieldFromIteratorGeneratorThrows()
  30. #2 {main}
  31. int(2)