bug37457.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. --TEST--
  2. Bug #37457 (Crash when an exception is thrown in accept() method of FilterIterator)
  3. --FILE--
  4. <?php
  5. class Collection implements Iterator
  6. {
  7. protected $array, $valid = false;
  8. public function __construct(array $a)
  9. {
  10. echo __METHOD__ . "\n";
  11. $this->array = $a;
  12. }
  13. public function current(): mixed
  14. {
  15. echo __METHOD__ . "\n";
  16. return current($this->array);
  17. }
  18. public function key(): mixed
  19. {
  20. echo __METHOD__ . "\n";
  21. return key($this->array);
  22. }
  23. public function next(): void
  24. {
  25. echo __METHOD__ . "\n";
  26. $this->valid = (false !== next($this->array));
  27. }
  28. public function valid(): bool
  29. {
  30. echo __METHOD__ . "\n";
  31. return $this->valid;
  32. }
  33. public function rewind(): void
  34. {
  35. echo __METHOD__ . "\n";
  36. $this->valid = (false !== reset($this->array));
  37. }
  38. }
  39. class TestFilter extends FilterIterator
  40. {
  41. public function accept(): bool
  42. {
  43. echo __METHOD__ . "\n";
  44. throw new Exception("Failure in Accept");
  45. }
  46. }
  47. $test = new TestFilter(new Collection(array(0)));
  48. try
  49. {
  50. foreach ($test as $item)
  51. {
  52. echo $item;
  53. }
  54. }
  55. catch (Exception $e)
  56. {
  57. var_dump($e->getMessage());
  58. }
  59. ?>
  60. --EXPECT--
  61. Collection::__construct
  62. Collection::rewind
  63. Collection::valid
  64. Collection::current
  65. Collection::key
  66. TestFilter::accept
  67. string(17) "Failure in Accept"