xref: /PHP-8.2/Zend/tests/bug32993.phpt (revision 75a678a7)
1--TEST--
2Bug #32993 (implemented Iterator function current() don't throw exception)
3--FILE--
4<?php
5class Test implements Iterator {
6
7    public $arr = array();
8
9    public function rewind(): void    { reset($this->arr); }
10    public function current(): mixed   { throw new Exception(); }
11    public function key(): mixed       { return key($this->arr); }
12    public function next(): void      { next($this->arr); }
13    public function valid(): bool     { return (current($this->arr) !== false); }
14}
15
16$t = new Test();
17$t->arr =  array(1, 2, 3);
18
19try {
20    foreach ($t as $v) {
21        echo "$v\n";
22    }
23} catch (Exception $e) {
24    ; // handle exception
25}
26echo "ok\n";
27?>
28--EXPECT--
29ok
30