1--TEST--
2is_a and is_subclass_of behaviour (with and without autoload)
3--FILE--
4<?php
5
6interface if_a {
7    function f_a();
8}
9
10interface if_b extends if_a {
11    function f_b();
12}
13
14class base {
15    function _is_a($sub) {
16
17        echo "\n>>> With Defined class\n";
18        echo str_pad('is_a( OBJECT:'.get_class($this).', '.$sub.') = ', 60) . (is_a($this, $sub) ? 'yes' : 'no')."\n";
19        echo str_pad('is_a( STRING:'.get_class($this).', '.$sub.') = ', 60). (is_a(get_class($this), $sub) ? 'yes' : 'no')."\n";
20        echo str_pad('is_a( STRING:'.get_class($this).', '.$sub.', true) = ', 60). (is_a(get_class($this), $sub, true) ? 'yes' : 'no')."\n";
21        echo str_pad('is_subclass_of( OBJECT:'.get_class($this).', '.$sub.') = ', 60).  (is_subclass_of($this, $sub) ? 'yes' : 'no')."\n";
22        echo str_pad('is_subclass_of( STRING:'.get_class($this).', '.$sub.') = ', 60). (is_subclass_of(get_class($this), $sub) ? 'yes' : 'no')."\n";
23        echo str_pad('is_subclass_of( STRING:'.get_class($this).', '.$sub.',false) = ', 60). (is_subclass_of(get_class($this), $sub , false) ? 'yes' : 'no')."\n";
24
25        // with autoload options..
26        echo ">>> With Undefined\n";
27        echo  str_pad('is_a( STRING:undefB, '.$sub.',true) = ', 60). (is_a('undefB', $sub, true) ? 'yes' : 'no')."\n";
28        echo  str_pad('is_a( STRING:undefB, '.$sub.') = ', 60). (is_a('undefB', $sub) ? 'yes' : 'no')."\n";
29        echo  str_pad('is_subclass_of( STRING:undefB, '.$sub.',false) = ', 60). (is_subclass_of('undefB', $sub, false) ? 'yes' : 'no')."\n";
30        echo  str_pad('is_subclass_of( STRING:undefB, '.$sub.') = ', 60). (is_subclass_of('undefB', $sub) ? 'yes' : 'no')."\n";
31    }
32    function test() {
33        echo $this->_is_a('base');
34        echo $this->_is_a('derived_a');
35        echo $this->_is_a('if_a');
36        echo $this->_is_a('undefA');
37        echo "\n";
38    }
39}
40
41class derived_a extends base implements if_a {
42    function f_a() {}
43}
44
45class derived_b extends base implements if_a, if_b {
46    function f_a() {}
47    function f_b() {}
48}
49
50class derived_c extends derived_a implements if_b {
51    function f_b() {}
52}
53
54class derived_d extends derived_c {
55}
56
57$t = new base();
58$t->test();
59
60$t = new derived_a();
61$t->test();
62
63spl_autoload_register(function ($name) {
64    echo ">>>> In autoload: ";
65    var_dump($name);
66});
67
68echo "NOW WITH AUTOLOAD\n\n";
69
70$t = new base();
71$t->test();
72
73$t = new derived_a();
74$t->test();
75
76$t = new derived_b();
77$t->test();
78
79
80
81
82
83?>
84--EXPECT--
85>>> With Defined class
86is_a( OBJECT:base, base) =                                  yes
87is_a( STRING:base, base) =                                  no
88is_a( STRING:base, base, true) =                            yes
89is_subclass_of( OBJECT:base, base) =                        no
90is_subclass_of( STRING:base, base) =                        no
91is_subclass_of( STRING:base, base,false) =                  no
92>>> With Undefined
93is_a( STRING:undefB, base,true) =                           no
94is_a( STRING:undefB, base) =                                no
95is_subclass_of( STRING:undefB, base,false) =                no
96is_subclass_of( STRING:undefB, base) =                      no
97
98>>> With Defined class
99is_a( OBJECT:base, derived_a) =                             no
100is_a( STRING:base, derived_a) =                             no
101is_a( STRING:base, derived_a, true) =                       no
102is_subclass_of( OBJECT:base, derived_a) =                   no
103is_subclass_of( STRING:base, derived_a) =                   no
104is_subclass_of( STRING:base, derived_a,false) =             no
105>>> With Undefined
106is_a( STRING:undefB, derived_a,true) =                      no
107is_a( STRING:undefB, derived_a) =                           no
108is_subclass_of( STRING:undefB, derived_a,false) =           no
109is_subclass_of( STRING:undefB, derived_a) =                 no
110
111>>> With Defined class
112is_a( OBJECT:base, if_a) =                                  no
113is_a( STRING:base, if_a) =                                  no
114is_a( STRING:base, if_a, true) =                            no
115is_subclass_of( OBJECT:base, if_a) =                        no
116is_subclass_of( STRING:base, if_a) =                        no
117is_subclass_of( STRING:base, if_a,false) =                  no
118>>> With Undefined
119is_a( STRING:undefB, if_a,true) =                           no
120is_a( STRING:undefB, if_a) =                                no
121is_subclass_of( STRING:undefB, if_a,false) =                no
122is_subclass_of( STRING:undefB, if_a) =                      no
123
124>>> With Defined class
125is_a( OBJECT:base, undefA) =                                no
126is_a( STRING:base, undefA) =                                no
127is_a( STRING:base, undefA, true) =                          no
128is_subclass_of( OBJECT:base, undefA) =                      no
129is_subclass_of( STRING:base, undefA) =                      no
130is_subclass_of( STRING:base, undefA,false) =                no
131>>> With Undefined
132is_a( STRING:undefB, undefA,true) =                         no
133is_a( STRING:undefB, undefA) =                              no
134is_subclass_of( STRING:undefB, undefA,false) =              no
135is_subclass_of( STRING:undefB, undefA) =                    no
136
137
138>>> With Defined class
139is_a( OBJECT:derived_a, base) =                             yes
140is_a( STRING:derived_a, base) =                             no
141is_a( STRING:derived_a, base, true) =                       yes
142is_subclass_of( OBJECT:derived_a, base) =                   yes
143is_subclass_of( STRING:derived_a, base) =                   yes
144is_subclass_of( STRING:derived_a, base,false) =             no
145>>> With Undefined
146is_a( STRING:undefB, base,true) =                           no
147is_a( STRING:undefB, base) =                                no
148is_subclass_of( STRING:undefB, base,false) =                no
149is_subclass_of( STRING:undefB, base) =                      no
150
151>>> With Defined class
152is_a( OBJECT:derived_a, derived_a) =                        yes
153is_a( STRING:derived_a, derived_a) =                        no
154is_a( STRING:derived_a, derived_a, true) =                  yes
155is_subclass_of( OBJECT:derived_a, derived_a) =              no
156is_subclass_of( STRING:derived_a, derived_a) =              no
157is_subclass_of( STRING:derived_a, derived_a,false) =        no
158>>> With Undefined
159is_a( STRING:undefB, derived_a,true) =                      no
160is_a( STRING:undefB, derived_a) =                           no
161is_subclass_of( STRING:undefB, derived_a,false) =           no
162is_subclass_of( STRING:undefB, derived_a) =                 no
163
164>>> With Defined class
165is_a( OBJECT:derived_a, if_a) =                             yes
166is_a( STRING:derived_a, if_a) =                             no
167is_a( STRING:derived_a, if_a, true) =                       yes
168is_subclass_of( OBJECT:derived_a, if_a) =                   yes
169is_subclass_of( STRING:derived_a, if_a) =                   yes
170is_subclass_of( STRING:derived_a, if_a,false) =             no
171>>> With Undefined
172is_a( STRING:undefB, if_a,true) =                           no
173is_a( STRING:undefB, if_a) =                                no
174is_subclass_of( STRING:undefB, if_a,false) =                no
175is_subclass_of( STRING:undefB, if_a) =                      no
176
177>>> With Defined class
178is_a( OBJECT:derived_a, undefA) =                           no
179is_a( STRING:derived_a, undefA) =                           no
180is_a( STRING:derived_a, undefA, true) =                     no
181is_subclass_of( OBJECT:derived_a, undefA) =                 no
182is_subclass_of( STRING:derived_a, undefA) =                 no
183is_subclass_of( STRING:derived_a, undefA,false) =           no
184>>> With Undefined
185is_a( STRING:undefB, undefA,true) =                         no
186is_a( STRING:undefB, undefA) =                              no
187is_subclass_of( STRING:undefB, undefA,false) =              no
188is_subclass_of( STRING:undefB, undefA) =                    no
189
190NOW WITH AUTOLOAD
191
192
193>>> With Defined class
194is_a( OBJECT:base, base) =                                  yes
195is_a( STRING:base, base) =                                  no
196is_a( STRING:base, base, true) =                            yes
197is_subclass_of( OBJECT:base, base) =                        no
198is_subclass_of( STRING:base, base) =                        no
199is_subclass_of( STRING:base, base,false) =                  no
200>>> With Undefined
201>>>> In autoload: string(6) "undefB"
202is_a( STRING:undefB, base,true) =                           no
203is_a( STRING:undefB, base) =                                no
204is_subclass_of( STRING:undefB, base,false) =                no
205>>>> In autoload: string(6) "undefB"
206is_subclass_of( STRING:undefB, base) =                      no
207
208>>> With Defined class
209is_a( OBJECT:base, derived_a) =                             no
210is_a( STRING:base, derived_a) =                             no
211is_a( STRING:base, derived_a, true) =                       no
212is_subclass_of( OBJECT:base, derived_a) =                   no
213is_subclass_of( STRING:base, derived_a) =                   no
214is_subclass_of( STRING:base, derived_a,false) =             no
215>>> With Undefined
216>>>> In autoload: string(6) "undefB"
217is_a( STRING:undefB, derived_a,true) =                      no
218is_a( STRING:undefB, derived_a) =                           no
219is_subclass_of( STRING:undefB, derived_a,false) =           no
220>>>> In autoload: string(6) "undefB"
221is_subclass_of( STRING:undefB, derived_a) =                 no
222
223>>> With Defined class
224is_a( OBJECT:base, if_a) =                                  no
225is_a( STRING:base, if_a) =                                  no
226is_a( STRING:base, if_a, true) =                            no
227is_subclass_of( OBJECT:base, if_a) =                        no
228is_subclass_of( STRING:base, if_a) =                        no
229is_subclass_of( STRING:base, if_a,false) =                  no
230>>> With Undefined
231>>>> In autoload: string(6) "undefB"
232is_a( STRING:undefB, if_a,true) =                           no
233is_a( STRING:undefB, if_a) =                                no
234is_subclass_of( STRING:undefB, if_a,false) =                no
235>>>> In autoload: string(6) "undefB"
236is_subclass_of( STRING:undefB, if_a) =                      no
237
238>>> With Defined class
239is_a( OBJECT:base, undefA) =                                no
240is_a( STRING:base, undefA) =                                no
241is_a( STRING:base, undefA, true) =                          no
242is_subclass_of( OBJECT:base, undefA) =                      no
243is_subclass_of( STRING:base, undefA) =                      no
244is_subclass_of( STRING:base, undefA,false) =                no
245>>> With Undefined
246>>>> In autoload: string(6) "undefB"
247is_a( STRING:undefB, undefA,true) =                         no
248is_a( STRING:undefB, undefA) =                              no
249is_subclass_of( STRING:undefB, undefA,false) =              no
250>>>> In autoload: string(6) "undefB"
251is_subclass_of( STRING:undefB, undefA) =                    no
252
253
254>>> With Defined class
255is_a( OBJECT:derived_a, base) =                             yes
256is_a( STRING:derived_a, base) =                             no
257is_a( STRING:derived_a, base, true) =                       yes
258is_subclass_of( OBJECT:derived_a, base) =                   yes
259is_subclass_of( STRING:derived_a, base) =                   yes
260is_subclass_of( STRING:derived_a, base,false) =             no
261>>> With Undefined
262>>>> In autoload: string(6) "undefB"
263is_a( STRING:undefB, base,true) =                           no
264is_a( STRING:undefB, base) =                                no
265is_subclass_of( STRING:undefB, base,false) =                no
266>>>> In autoload: string(6) "undefB"
267is_subclass_of( STRING:undefB, base) =                      no
268
269>>> With Defined class
270is_a( OBJECT:derived_a, derived_a) =                        yes
271is_a( STRING:derived_a, derived_a) =                        no
272is_a( STRING:derived_a, derived_a, true) =                  yes
273is_subclass_of( OBJECT:derived_a, derived_a) =              no
274is_subclass_of( STRING:derived_a, derived_a) =              no
275is_subclass_of( STRING:derived_a, derived_a,false) =        no
276>>> With Undefined
277>>>> In autoload: string(6) "undefB"
278is_a( STRING:undefB, derived_a,true) =                      no
279is_a( STRING:undefB, derived_a) =                           no
280is_subclass_of( STRING:undefB, derived_a,false) =           no
281>>>> In autoload: string(6) "undefB"
282is_subclass_of( STRING:undefB, derived_a) =                 no
283
284>>> With Defined class
285is_a( OBJECT:derived_a, if_a) =                             yes
286is_a( STRING:derived_a, if_a) =                             no
287is_a( STRING:derived_a, if_a, true) =                       yes
288is_subclass_of( OBJECT:derived_a, if_a) =                   yes
289is_subclass_of( STRING:derived_a, if_a) =                   yes
290is_subclass_of( STRING:derived_a, if_a,false) =             no
291>>> With Undefined
292>>>> In autoload: string(6) "undefB"
293is_a( STRING:undefB, if_a,true) =                           no
294is_a( STRING:undefB, if_a) =                                no
295is_subclass_of( STRING:undefB, if_a,false) =                no
296>>>> In autoload: string(6) "undefB"
297is_subclass_of( STRING:undefB, if_a) =                      no
298
299>>> With Defined class
300is_a( OBJECT:derived_a, undefA) =                           no
301is_a( STRING:derived_a, undefA) =                           no
302is_a( STRING:derived_a, undefA, true) =                     no
303is_subclass_of( OBJECT:derived_a, undefA) =                 no
304is_subclass_of( STRING:derived_a, undefA) =                 no
305is_subclass_of( STRING:derived_a, undefA,false) =           no
306>>> With Undefined
307>>>> In autoload: string(6) "undefB"
308is_a( STRING:undefB, undefA,true) =                         no
309is_a( STRING:undefB, undefA) =                              no
310is_subclass_of( STRING:undefB, undefA,false) =              no
311>>>> In autoload: string(6) "undefB"
312is_subclass_of( STRING:undefB, undefA) =                    no
313
314
315>>> With Defined class
316is_a( OBJECT:derived_b, base) =                             yes
317is_a( STRING:derived_b, base) =                             no
318is_a( STRING:derived_b, base, true) =                       yes
319is_subclass_of( OBJECT:derived_b, base) =                   yes
320is_subclass_of( STRING:derived_b, base) =                   yes
321is_subclass_of( STRING:derived_b, base,false) =             no
322>>> With Undefined
323>>>> In autoload: string(6) "undefB"
324is_a( STRING:undefB, base,true) =                           no
325is_a( STRING:undefB, base) =                                no
326is_subclass_of( STRING:undefB, base,false) =                no
327>>>> In autoload: string(6) "undefB"
328is_subclass_of( STRING:undefB, base) =                      no
329
330>>> With Defined class
331is_a( OBJECT:derived_b, derived_a) =                        no
332is_a( STRING:derived_b, derived_a) =                        no
333is_a( STRING:derived_b, derived_a, true) =                  no
334is_subclass_of( OBJECT:derived_b, derived_a) =              no
335is_subclass_of( STRING:derived_b, derived_a) =              no
336is_subclass_of( STRING:derived_b, derived_a,false) =        no
337>>> With Undefined
338>>>> In autoload: string(6) "undefB"
339is_a( STRING:undefB, derived_a,true) =                      no
340is_a( STRING:undefB, derived_a) =                           no
341is_subclass_of( STRING:undefB, derived_a,false) =           no
342>>>> In autoload: string(6) "undefB"
343is_subclass_of( STRING:undefB, derived_a) =                 no
344
345>>> With Defined class
346is_a( OBJECT:derived_b, if_a) =                             yes
347is_a( STRING:derived_b, if_a) =                             no
348is_a( STRING:derived_b, if_a, true) =                       yes
349is_subclass_of( OBJECT:derived_b, if_a) =                   yes
350is_subclass_of( STRING:derived_b, if_a) =                   yes
351is_subclass_of( STRING:derived_b, if_a,false) =             no
352>>> With Undefined
353>>>> In autoload: string(6) "undefB"
354is_a( STRING:undefB, if_a,true) =                           no
355is_a( STRING:undefB, if_a) =                                no
356is_subclass_of( STRING:undefB, if_a,false) =                no
357>>>> In autoload: string(6) "undefB"
358is_subclass_of( STRING:undefB, if_a) =                      no
359
360>>> With Defined class
361is_a( OBJECT:derived_b, undefA) =                           no
362is_a( STRING:derived_b, undefA) =                           no
363is_a( STRING:derived_b, undefA, true) =                     no
364is_subclass_of( OBJECT:derived_b, undefA) =                 no
365is_subclass_of( STRING:derived_b, undefA) =                 no
366is_subclass_of( STRING:derived_b, undefA,false) =           no
367>>> With Undefined
368>>>> In autoload: string(6) "undefB"
369is_a( STRING:undefB, undefA,true) =                         no
370is_a( STRING:undefB, undefA) =                              no
371is_subclass_of( STRING:undefB, undefA,false) =              no
372>>>> In autoload: string(6) "undefB"
373is_subclass_of( STRING:undefB, undefA) =                    no
374