@@ -10597,7 +10597,7 @@ static zend_op *zend_delayed_compile_var(znode *result, zend_ast *ast, uint32_t
10597
10597
}
10598
10598
/* }}} */
10599
10599
10600
- static void zend_eval_const_expr_inner (zend_ast * * ast_ptr , void * ctx ) /* {{{ */
10600
+ static void zend_eval_const_expr (zend_ast * * ast_ptr ) /* {{{ */
10601
10601
{
10602
10602
zend_ast * ast = * ast_ptr ;
10603
10603
zval result ;
@@ -10606,25 +10606,10 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
10606
10606
return ;
10607
10607
}
10608
10608
10609
- /* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
10610
- if (ast -> kind == ZEND_AST_DIM
10611
- && (ast -> attr & ZEND_DIM_IS )
10612
- && ast -> child [0 ]-> kind == ZEND_AST_DIM ) {
10613
- ast -> child [0 ]-> attr |= ZEND_DIM_IS ;
10614
- }
10615
-
10616
- /* We don't want to evaluate the class name of ZEND_AST_CLASS_NAME nodes. We need to be able to
10617
- * differenciate between literal class names and expressions that evaluate to strings. Strings
10618
- * are not actually allowed in ::class expressions.
10619
- *
10620
- * ZEND_AST_COALESCE and ZEND_AST_CONDITIONAL will manually evaluate only the children for the
10621
- * taken paths. */
10622
- if (ast -> kind != ZEND_AST_CLASS_NAME && ast -> kind != ZEND_AST_COALESCE && ast -> kind != ZEND_AST_CONDITIONAL ) {
10623
- zend_ast_apply (ast , zend_eval_const_expr_inner , ctx );
10624
- }
10625
-
10626
10609
switch (ast -> kind ) {
10627
10610
case ZEND_AST_BINARY_OP :
10611
+ zend_eval_const_expr (& ast -> child [0 ]);
10612
+ zend_eval_const_expr (& ast -> child [1 ]);
10628
10613
if (ast -> child [0 ]-> kind != ZEND_AST_ZVAL || ast -> child [1 ]-> kind != ZEND_AST_ZVAL ) {
10629
10614
return ;
10630
10615
}
@@ -10637,6 +10622,8 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
10637
10622
break ;
10638
10623
case ZEND_AST_GREATER :
10639
10624
case ZEND_AST_GREATER_EQUAL :
10625
+ zend_eval_const_expr (& ast -> child [0 ]);
10626
+ zend_eval_const_expr (& ast -> child [1 ]);
10640
10627
if (ast -> child [0 ]-> kind != ZEND_AST_ZVAL || ast -> child [1 ]-> kind != ZEND_AST_ZVAL ) {
10641
10628
return ;
10642
10629
}
@@ -10648,6 +10635,8 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
10648
10635
case ZEND_AST_OR :
10649
10636
{
10650
10637
bool child0_is_true , child1_is_true ;
10638
+ zend_eval_const_expr (& ast -> child [0 ]);
10639
+ zend_eval_const_expr (& ast -> child [1 ]);
10651
10640
if (ast -> child [0 ]-> kind != ZEND_AST_ZVAL ) {
10652
10641
return ;
10653
10642
}
@@ -10671,6 +10660,7 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
10671
10660
break ;
10672
10661
}
10673
10662
case ZEND_AST_UNARY_OP :
10663
+ zend_eval_const_expr (& ast -> child [0 ]);
10674
10664
if (ast -> child [0 ]-> kind != ZEND_AST_ZVAL ) {
10675
10665
return ;
10676
10666
}
@@ -10681,6 +10671,7 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
10681
10671
break ;
10682
10672
case ZEND_AST_UNARY_PLUS :
10683
10673
case ZEND_AST_UNARY_MINUS :
10674
+ zend_eval_const_expr (& ast -> child [0 ]);
10684
10675
if (ast -> child [0 ]-> kind != ZEND_AST_ZVAL ) {
10685
10676
return ;
10686
10677
}
@@ -10751,6 +10742,13 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
10751
10742
zend_error (E_COMPILE_ERROR , "Array and string offset access syntax with curly braces is no longer supported" );
10752
10743
}
10753
10744
10745
+ /* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
10746
+ if ((ast -> attr & ZEND_DIM_IS ) && ast -> child [0 ]-> kind == ZEND_AST_DIM ) {
10747
+ ast -> child [0 ]-> attr |= ZEND_DIM_IS ;
10748
+ }
10749
+
10750
+ zend_eval_const_expr (& ast -> child [0 ]);
10751
+ zend_eval_const_expr (& ast -> child [1 ]);
10754
10752
if (ast -> child [0 ]-> kind != ZEND_AST_ZVAL || ast -> child [1 ]-> kind != ZEND_AST_ZVAL ) {
10755
10753
return ;
10756
10754
}
@@ -10828,6 +10826,9 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
10828
10826
zend_ast * name_ast ;
10829
10827
zend_string * resolved_name ;
10830
10828
10829
+ zend_eval_const_expr (& ast -> child [0 ]);
10830
+ zend_eval_const_expr (& ast -> child [1 ]);
10831
+
10831
10832
if (UNEXPECTED (ast -> child [1 ]-> kind != ZEND_AST_ZVAL
10832
10833
|| Z_TYPE_P (zend_ast_get_zval (ast -> child [1 ])) != IS_STRING )) {
10833
10834
return ;
@@ -10857,6 +10858,33 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
10857
10858
}
10858
10859
break ;
10859
10860
}
10861
+ // TODO: We should probably use zend_ast_apply to recursively walk nodes without
10862
+ // special handling. It is required that all nodes that are part of a const expr
10863
+ // are visited. Probably we should be distinguishing evaluation of const expr and
10864
+ // normal exprs here.
10865
+ case ZEND_AST_ARG_LIST :
10866
+ {
10867
+ zend_ast_list * list = zend_ast_get_list (ast );
10868
+ for (uint32_t i = 0 ; i < list -> children ; i ++ ) {
10869
+ zend_eval_const_expr (& list -> child [i ]);
10870
+ }
10871
+ return ;
10872
+ }
10873
+ case ZEND_AST_NEW :
10874
+ zend_eval_const_expr (& ast -> child [0 ]);
10875
+ zend_eval_const_expr (& ast -> child [1 ]);
10876
+ return ;
10877
+ case ZEND_AST_NAMED_ARG :
10878
+ zend_eval_const_expr (& ast -> child [1 ]);
10879
+ return ;
10880
+ case ZEND_AST_CONST_ENUM_INIT :
10881
+ zend_eval_const_expr (& ast -> child [2 ]);
10882
+ return ;
10883
+ case ZEND_AST_PROP :
10884
+ case ZEND_AST_NULLSAFE_PROP :
10885
+ zend_eval_const_expr (& ast -> child [0 ]);
10886
+ zend_eval_const_expr (& ast -> child [1 ]);
10887
+ return ;
10860
10888
default :
10861
10889
return ;
10862
10890
}
@@ -10865,9 +10893,3 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
10865
10893
* ast_ptr = zend_ast_create_zval (& result );
10866
10894
}
10867
10895
/* }}} */
10868
-
10869
-
10870
- static void zend_eval_const_expr (zend_ast * * ast_ptr ) /* {{{ */
10871
- {
10872
- zend_eval_const_expr_inner (ast_ptr , NULL );
10873
- }
0 commit comments