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