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