bug71013.phpt 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --TEST--
  2. Bug #71013 (Incorrect exception handler with yield from)
  3. --FILE--
  4. <?php
  5. class FooBar implements Iterator {
  6. function __construct() { echo "Constructing new FooBar\n"; }
  7. function __destruct() { echo "Destructing FooBar\n"; }
  8. function current (): mixed { throw new Exception; }
  9. function key (): int { return 0; }
  10. function next (): void {}
  11. function rewind (): void {}
  12. function valid (): bool { return true; }
  13. }
  14. function foo() {
  15. try {
  16. $f = new FooBar;
  17. yield from $f;
  18. } catch (Exception $e) {
  19. echo "[foo()] Caught Exception\n";
  20. }
  21. }
  22. function bar() {
  23. echo "Starting bar()\n";
  24. $x = foo();
  25. try {
  26. var_dump($x->current());
  27. } catch (Exception $e) {
  28. echo "[bar()] Caught Exception\n";
  29. }
  30. echo "Unsetting \$x\n";
  31. unset($x);
  32. echo "Finishing bar()\n";
  33. }
  34. bar();
  35. ?>
  36. --EXPECT--
  37. Starting bar()
  38. Constructing new FooBar
  39. [foo()] Caught Exception
  40. Destructing FooBar
  41. NULL
  42. Unsetting $x
  43. Finishing bar()