xref: /PHP-8.2/ext/opcache/tests/opt/prop_types.phpt (revision 4df85860)
1--TEST--
2Property types in inference
3--INI--
4opcache.enable=1
5opcache.enable_cli=1
6opcache.optimization_level=-1
7opcache.opt_debug_level=0x200000
8opcache.preload=
9--EXTENSIONS--
10opcache
11--FILE--
12<?php
13
14class Test {
15    public bool $public;
16    protected int $protected;
17    private float $private;
18
19    public function inTest() {
20        var_dump($this->public, $this->protected, $this->private);
21    }
22
23    public function inTestWithTest2(Test2 $test2) {
24        var_dump($test2->public, $test2->protected, $test2->private);
25    }
26}
27
28class Test2 extends Test {
29    private array $private;
30
31    public function inTest2() {
32        var_dump($this->public, $this->protected, $this->private);
33    }
34}
35
36function noScope(Test $test) {
37    var_dump($test->public, $test->protected, $test->private);
38}
39
40?>
41--EXPECTF--
42$_main:
43     ; (lines=1, args=0, vars=0, tmps=%d, ssa_vars=0, no_loops)
44     ; (before dfa pass)
45     ; %s
46     ; return  [long] RANGE[1..1]
47BB0:
48     ; start exit lines=[0-0]
49     ; level=0
500000 RETURN int(1)
51
52noScope:
53     ; (lines=10, args=1, vars=1, tmps=%d, ssa_vars=5, no_loops)
54     ; (before dfa pass)
55     ; %s
56     ; return  [null] RANGE[0..0]
57     ; #0.CV0($test) NOVAL [undef]
58BB0:
59     ; start exit lines=[0-9]
60     ; level=0
610000 #1.CV0($test) [object (instanceof Test)] = RECV 1
620001 INIT_FCALL 3 %d string("var_dump")
630002 #2.T1 [bool] = FETCH_OBJ_R #1.CV0($test) [object (instanceof Test)] string("public")
640003 SEND_VAL #2.T1 [bool] 1
650004 #3.T2 [any] = FETCH_OBJ_R #1.CV0($test) [object (instanceof Test)] string("protected")
660005 SEND_VAL #3.T2 [any] 2
670006 #4.T3 [any] = FETCH_OBJ_R #1.CV0($test) [object (instanceof Test)] string("private")
680007 SEND_VAL #4.T3 [any] 3
690008 DO_ICALL
700009 RETURN null
71
72Test::inTest:
73     ; (lines=9, args=0, vars=0, tmps=%d, ssa_vars=3, no_loops)
74     ; (before dfa pass)
75     ; %s
76     ; return  [null] RANGE[0..0]
77BB0:
78     ; start exit lines=[0-8]
79     ; level=0
800000 INIT_FCALL 3 %d string("var_dump")
810001 #0.T0 [bool] = FETCH_OBJ_R THIS string("public")
820002 SEND_VAL #0.T0 [bool] 1
830003 #1.T1 [long] = FETCH_OBJ_R THIS string("protected")
840004 SEND_VAL #1.T1 [long] 2
850005 #2.T2 [double] = FETCH_OBJ_R THIS string("private")
860006 SEND_VAL #2.T2 [double] 3
870007 DO_ICALL
880008 RETURN null
89
90Test::inTestWithTest2:
91     ; (lines=10, args=1, vars=1, tmps=%d, ssa_vars=5, no_loops)
92     ; (before dfa pass)
93     ; %s
94     ; return  [null] RANGE[0..0]
95     ; #0.CV0($test2) NOVAL [undef]
96BB0:
97     ; start exit lines=[0-9]
98     ; level=0
990000 #1.CV0($test2) [object (instanceof Test2)] = RECV 1
1000001 INIT_FCALL 3 %d string("var_dump")
1010002 #2.T1 [bool] = FETCH_OBJ_R #1.CV0($test2) [object (instanceof Test2)] string("public")
1020003 SEND_VAL #2.T1 [bool] 1
1030004 #3.T2 [long] = FETCH_OBJ_R #1.CV0($test2) [object (instanceof Test2)] string("protected")
1040005 SEND_VAL #3.T2 [long] 2
1050006 #4.T3 [double] = FETCH_OBJ_R #1.CV0($test2) [object (instanceof Test2)] string("private")
1060007 SEND_VAL #4.T3 [double] 3
1070008 DO_ICALL
1080009 RETURN null
109
110Test2::inTest2:
111     ; (lines=9, args=0, vars=0, tmps=%d, ssa_vars=3, no_loops)
112     ; (before dfa pass)
113     ; %s
114     ; return  [null] RANGE[0..0]
115BB0:
116     ; start exit lines=[0-8]
117     ; level=0
1180000 INIT_FCALL 3 %d string("var_dump")
1190001 #0.T0 [bool] = FETCH_OBJ_R THIS string("public")
1200002 SEND_VAL #0.T0 [bool] 1
1210003 #1.T1 [long] = FETCH_OBJ_R THIS string("protected")
1220004 SEND_VAL #1.T1 [long] 2
1230005 #2.T2 [array of [any, ref]] = FETCH_OBJ_R THIS string("private")
1240006 SEND_VAL #2.T2 [array of [any, ref]] 3
1250007 DO_ICALL
1260008 RETURN null
127