xref: /PHP-7.4/ext/opcache/tests/opt/prop_types.phpt (revision 12edc453)
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--SKIPIF--
10<?php require_once('skipif.inc'); ?>
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: ; (lines=1, args=0, vars=0, tmps=0, ssa_vars=0, no_loops)
43    ; (before dfa pass)
44    ; %s
45    ; return  [long] RANGE[1..1]
46BB0: start exit lines=[0-0]
47    ; level=0
48            RETURN int(1)
49
50noScope: ; (lines=10, args=1, vars=1, tmps=1, ssa_vars=5, no_loops)
51    ; (before dfa pass)
52    ; %s
53    ; return  [null] RANGE[0..0]
54    ; #0.CV0($test) NOVAL [undef]
55BB0: start exit lines=[0-9]
56    ; level=0
57            #1.CV0($test) [object (instanceof Test)] = RECV 1
58            INIT_FCALL 3 %d string("var_dump")
59            #2.T1 [bool] = FETCH_OBJ_R #1.CV0($test) [object (instanceof Test)] string("public")
60            SEND_VAL #2.T1 [bool] 1
61            #3.T1 [any] = FETCH_OBJ_R #1.CV0($test) [object (instanceof Test)] string("protected")
62            SEND_VAL #3.T1 [any] 2
63            #4.T1 [any] = FETCH_OBJ_R #1.CV0($test) [object (instanceof Test)] string("private")
64            SEND_VAL #4.T1 [any] 3
65            DO_ICALL
66            RETURN null
67
68Test::inTest: ; (lines=9, args=0, vars=0, tmps=1, ssa_vars=3, no_loops)
69    ; (before dfa pass)
70    ; %s
71    ; return  [null] RANGE[0..0]
72BB0: start exit lines=[0-8]
73    ; level=0
74            INIT_FCALL 3 %d string("var_dump")
75            #0.T0 [bool] = FETCH_OBJ_R THIS string("public")
76            SEND_VAL #0.T0 [bool] 1
77            #1.T0 [long] = FETCH_OBJ_R THIS string("protected")
78            SEND_VAL #1.T0 [long] 2
79            #2.T0 [double] = FETCH_OBJ_R THIS string("private")
80            SEND_VAL #2.T0 [double] 3
81            DO_ICALL
82            RETURN null
83
84Test::inTestWithTest2: ; (lines=10, args=1, vars=1, tmps=1, ssa_vars=5, no_loops)
85    ; (before dfa pass)
86    ; %s
87    ; return  [null] RANGE[0..0]
88    ; #0.CV0($test2) NOVAL [undef]
89BB0: start exit lines=[0-9]
90    ; level=0
91            #1.CV0($test2) [object (instanceof Test2)] = RECV 1
92            INIT_FCALL 3 %d string("var_dump")
93            #2.T1 [bool] = FETCH_OBJ_R #1.CV0($test2) [object (instanceof Test2)] string("public")
94            SEND_VAL #2.T1 [bool] 1
95            #3.T1 [long] = FETCH_OBJ_R #1.CV0($test2) [object (instanceof Test2)] string("protected")
96            SEND_VAL #3.T1 [long] 2
97            #4.T1 [double] = FETCH_OBJ_R #1.CV0($test2) [object (instanceof Test2)] string("private")
98            SEND_VAL #4.T1 [double] 3
99            DO_ICALL
100            RETURN null
101
102Test2::inTest2: ; (lines=9, args=0, vars=0, tmps=1, ssa_vars=3, no_loops)
103    ; (before dfa pass)
104    ; %s
105    ; return  [null] RANGE[0..0]
106BB0: start exit lines=[0-8]
107    ; level=0
108            INIT_FCALL 3 %d string("var_dump")
109            #0.T0 [bool] = FETCH_OBJ_R THIS string("public")
110            SEND_VAL #0.T0 [bool] 1
111            #1.T0 [long] = FETCH_OBJ_R THIS string("protected")
112            SEND_VAL #1.T0 [long] 2
113            #2.T0 [array of [any, ref]] = FETCH_OBJ_R THIS string("private")
114            SEND_VAL #2.T0 [array of [any, ref]] 3
115            DO_ICALL
116            RETURN null
117