File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Check that const exprs are pre-evaluated in new arguments
3
+ --FILE--
4
+ <?php
5
+
6
+ class C {
7
+ public function __construct (public $ x ) {}
8
+ }
9
+ function test (
10
+ $ a = new C (__CLASS__ ),
11
+ $ b = new C (__FUNCTION__ ),
12
+ $ c = new C (x: __FILE__ ),
13
+ ) {
14
+ var_dump ($ a , $ b , $ c );
15
+ }
16
+ test ();
17
+
18
+ ?>
19
+ --EXPECTF--
20
+ object(C)#1 (1) {
21
+ ["x"]=>
22
+ string(0) ""
23
+ }
24
+ object(C)#2 (1) {
25
+ ["x"]=>
26
+ string(4) "test"
27
+ }
28
+ object(C)#3 (1) {
29
+ ["x"]=>
30
+ string(%d) "%snew_arg_eval.php"
31
+ }
Original file line number Diff line number Diff line change @@ -10164,6 +10164,25 @@ void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
10164
10164
}
10165
10165
break ;
10166
10166
}
10167
+ // TODO: We should probably use zend_ast_apply to recursively walk nodes without
10168
+ // special handling. It is required that all nodes that are part of a const expr
10169
+ // are visited. Probably we should be distinguishing evaluation of const expr and
10170
+ // normal exprs here.
10171
+ case ZEND_AST_ARG_LIST :
10172
+ {
10173
+ zend_ast_list * list = zend_ast_get_list (ast );
10174
+ for (uint32_t i = 0 ; i < list -> children ; i ++ ) {
10175
+ zend_eval_const_expr (& list -> child [i ]);
10176
+ }
10177
+ return ;
10178
+ }
10179
+ case ZEND_AST_NEW :
10180
+ zend_eval_const_expr (& ast -> child [0 ]);
10181
+ zend_eval_const_expr (& ast -> child [1 ]);
10182
+ return ;
10183
+ case ZEND_AST_NAMED_ARG :
10184
+ zend_eval_const_expr (& ast -> child [1 ]);
10185
+ return ;
10167
10186
default :
10168
10187
return ;
10169
10188
}
You can’t perform that action at this time.
0 commit comments