xref: /PHP-8.1/ext/spl/tests/bug54384.phpt (revision b3e08881)
1--TEST--
2Bug #54384: Several SPL classes crash when the parent constructor is not called
3--FILE--
4<?php
5
6function test($f) {
7    try {
8        $f();
9        echo "ran normally (unexpected)\n\n";
10    } catch (\Error $e) {
11        echo "Error (expected)\n";
12    }
13}
14
15echo "IteratorIterator... ";
16class IteratorIteratorTest extends IteratorIterator {
17    function __construct(){}
18}
19test( function() {
20    $o = new IteratorIteratorTest;
21    $o->rewind();
22} );
23
24echo "FilterIterator... ";
25class FilterIteratorTest extends FilterIterator {
26    function __construct(){}
27    function accept(): bool {}
28}
29test( function() {
30    $o = new FilterIteratorTest;
31    $o->rewind();
32} );
33
34echo "RecursiveFilterIterator... ";
35class RecursiveFilterIteratorTest extends RecursiveFilterIterator {
36    function __construct(){}
37    function accept(): bool {}
38}
39test( function() {
40$o = new RecursiveFilterIteratorTest;
41$o->hasChildren();
42} );
43
44echo "ParentIterator... ";
45class ParentIteratorTest extends ParentIterator {
46    function __construct(){}
47}
48test ( function() {
49$o = new ParentIteratorTest;
50$o->accept();
51} );
52
53echo "LimitIterator... ";
54class LimitIteratorTest extends LimitIterator {
55    function __construct(){}
56}
57test ( function() {
58$o = new LimitIteratorTest;
59$o->rewind();
60} );
61
62echo "CachingIterator... ";
63class CachingIteratorTest extends CachingIterator {
64    function __construct(){}
65}
66test ( function() {
67$o = new CachingIteratorTest;
68$o->rewind();
69} );
70
71echo "RecursiveCachingIterator... ";
72class RecursiveCachingIteratorTest extends RecursiveCachingIterator {
73    function __construct(){}
74}
75test ( function() {
76$o = new RecursiveCachingIteratorTest;
77$o->rewind();
78} );
79
80echo "NoRewindIterator... ";
81class NoRewindIteratorTest extends NoRewindIterator {
82    function __construct(){}
83}
84test ( function() {
85$o = new NoRewindIteratorTest;
86$o->valid();
87} );
88
89echo "RegexIterator... ";
90class RegexIteratorTest extends RegexIterator {
91    function __construct(){}
92}
93test ( function() {
94$o = new RegexIteratorTest;
95$o->rewind();
96} );
97
98echo "RecursiveRegexIterator... ";
99class RecursiveRegexIteratorTest extends RecursiveRegexIterator {
100    function __construct(){}
101}
102test ( function() {
103$o = new RecursiveRegexIteratorTest;
104$o->hasChildren();
105} );
106
107echo "GlobIterator... ";
108class GlobIteratorTest extends GlobIterator {
109    function __construct(){}
110}
111test ( function() {
112$o = new GlobIteratorTest;
113$o->count();
114} );
115
116echo "SplFileObject... ";
117class SplFileObjectTest extends SplFileObject {
118    function __construct(){}
119}
120test ( function() {
121$o = new SplFileObjectTest;
122$o->rewind();
123} );
124
125echo "SplTempFileObject... ";
126class SplTempFileObjectTest extends SplTempFileObject {
127    function __construct(){}
128}
129test ( function() {
130$o = new SplTempFileObjectTest;
131$o->rewind();
132} );
133
134echo "AppendIterator... ";
135class AppendIteratorTest extends AppendIterator {
136    function __construct(){}
137}
138test ( function() {
139$o = new AppendIteratorTest;
140foreach ($o as $a) {
141echo $a,"\n";
142}
143} );
144
145echo "InfiniteIterator... ";
146class InfiniteIteratorTest extends InfiniteIterator {
147    function __construct(){}
148}
149test ( function() {
150$o = new InfiniteIteratorTest;
151foreach ($o as $a) {
152echo $a,"\n";
153}
154} );
155?>
156--EXPECT--
157IteratorIterator... Error (expected)
158FilterIterator... Error (expected)
159RecursiveFilterIterator... Error (expected)
160ParentIterator... Error (expected)
161LimitIterator... Error (expected)
162CachingIterator... Error (expected)
163RecursiveCachingIterator... Error (expected)
164NoRewindIterator... Error (expected)
165RegexIterator... Error (expected)
166RecursiveRegexIterator... Error (expected)
167GlobIterator... Error (expected)
168SplFileObject... Error (expected)
169SplTempFileObject... Error (expected)
170AppendIterator... Error (expected)
171InfiniteIterator... Error (expected)
172