xref: /PHP-7.4/ext/reflection/tests/bug43926.phpt (revision 2fb4ea9c)
1--TEST--
2Bug #43926 (isInstance() isn't equivalent to instanceof operator)
3--FILE--
4<?php
5
6class E {
7}
8class D extends E {
9}
10
11class A extends D {
12}
13
14class C extends A {
15}
16
17$ra = new ReflectionClass('A');
18$rc = new ReflectionClass('C');
19$rd = new ReflectionClass('D');
20$re = new ReflectionClass('E');
21
22$ca = $ra->newInstance();
23$cc = $rc->newInstance();
24$cd = $rd->newInstance();
25$ce = $re->newInstance();
26
27print("Is? A ". ($ra->isInstance($ca) ? 'true' : 'false') .", instanceof: ". (($ca instanceof A) ? 'true' : 'false') ."\n");
28print("Is? C ". ($rc->isInstance($ca) ? 'true' : 'false') .", instanceof: ". (($ca instanceof C) ? 'true' : 'false') ."\n");
29print("Is? D ". ($rd->isInstance($ca) ? 'true' : 'false') .", instanceof: ". (($ca instanceof D) ? 'true' : 'false') ."\n");
30print("Is? E ". ($re->isInstance($ca) ? 'true' : 'false') .", instanceof: ". (($ca instanceof E) ? 'true' : 'false') ."\n");
31print "-\n";
32print("Is? A ". ($ra->isInstance($cc) ? 'true' : 'false') .", instanceof: ". (($cc instanceof A) ? 'true' : 'false') ."\n");
33print("Is? C ". ($rc->isInstance($cc) ? 'true' : 'false') .", instanceof: ". (($cc instanceof C) ? 'true' : 'false') ."\n");
34print("Is? D ". ($rd->isInstance($cc) ? 'true' : 'false') .", instanceof: ". (($cc instanceof D) ? 'true' : 'false') ."\n");
35print("Is? E ". ($re->isInstance($cc) ? 'true' : 'false') .", instanceof: ". (($cc instanceof E) ? 'true' : 'false') ."\n");
36print "-\n";
37print("Is? A ". ($ra->isInstance($cd) ? 'true' : 'false') .", instanceof: ". (($cd instanceof A) ? 'true' : 'false') ."\n");
38print("Is? C ". ($rc->isInstance($cd) ? 'true' : 'false') .", instanceof: ". (($cd instanceof C) ? 'true' : 'false') ."\n");
39print("Is? D ". ($rd->isInstance($cd) ? 'true' : 'false') .", instanceof: ". (($cd instanceof D) ? 'true' : 'false') ."\n");
40print("Is? E ". ($re->isInstance($cd) ? 'true' : 'false') .", instanceof: ". (($cd instanceof E) ? 'true' : 'false') ."\n");
41print "-\n";
42print("Is? A ". ($ra->isInstance($ce) ? 'true' : 'false') .", instanceof: ". (($ce instanceof A) ? 'true' : 'false') ."\n");
43print("Is? C ". ($rc->isInstance($ce) ? 'true' : 'false') .", instanceof: ". (($ce instanceof C) ? 'true' : 'false') ."\n");
44print("Is? D ". ($rd->isInstance($ce) ? 'true' : 'false') .", instanceof: ". (($ce instanceof D) ? 'true' : 'false') ."\n");
45print("Is? E ". ($re->isInstance($ce) ? 'true' : 'false') .", instanceof: ". (($ce instanceof E) ? 'true' : 'false') ."\n");
46
47?>
48--EXPECT--
49Is? A true, instanceof: true
50Is? C false, instanceof: false
51Is? D true, instanceof: true
52Is? E true, instanceof: true
53-
54Is? A true, instanceof: true
55Is? C true, instanceof: true
56Is? D true, instanceof: true
57Is? E true, instanceof: true
58-
59Is? A false, instanceof: false
60Is? C false, instanceof: false
61Is? D true, instanceof: true
62Is? E true, instanceof: true
63-
64Is? A false, instanceof: false
65Is? C false, instanceof: false
66Is? D false, instanceof: false
67Is? E true, instanceof: true
68