bug32674.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --TEST--
  2. Bug #32674 (exception in iterator causes crash)
  3. --FILE--
  4. <?php
  5. class collection implements Iterator {
  6. private $_elements = array();
  7. public function __construct() {
  8. }
  9. public function rewind(): void {
  10. reset($this->_elements);
  11. }
  12. public function count(): int {
  13. return count($this->_elements);
  14. }
  15. public function current(): mixed {
  16. $element = current($this->_elements);
  17. return $element;
  18. }
  19. public function next(): void {
  20. $element = next($this->_elements);
  21. $element;
  22. }
  23. public function key(): mixed {
  24. $this->_fillCollection();
  25. $element = key($this->_elements);
  26. return $element;
  27. }
  28. public function valid(): bool {
  29. throw new Exception('shit happened');
  30. return ($this->current() !== false);
  31. }
  32. }
  33. class class2 {
  34. public $dummy;
  35. }
  36. $obj = new class2();
  37. $col = new collection();
  38. try {
  39. foreach($col as $co) {
  40. //irrelevant
  41. }
  42. echo 'shouldn`t get here';
  43. //$dummy = 'this will not crash';
  44. $obj->dummy = 'this will crash';
  45. } catch (Exception $e) {
  46. echo "ok\n";
  47. }
  48. ?>
  49. --EXPECT--
  50. ok