@@ -9750,8 +9750,13 @@ static void zend_compile_magic_const(znode *result, zend_ast *ast) /* {{{ */
9750
9750
}
9751
9751
/* }}} */
9752
9752
9753
- static bool zend_is_allowed_in_const_expr (zend_ast_kind kind ) /* {{{ */
9753
+ static bool zend_is_allowed_in_const_expr (zend_ast * ast ) /* {{{ */
9754
9754
{
9755
+ zend_ast_kind kind = ast -> kind ;
9756
+ if (kind == ZEND_AST_CALL && ast -> child [1 ]-> kind == ZEND_AST_CALLABLE_CONVERT ) {
9757
+ return true;
9758
+ }
9759
+
9755
9760
return kind == ZEND_AST_ZVAL || kind == ZEND_AST_BINARY_OP
9756
9761
|| kind == ZEND_AST_GREATER || kind == ZEND_AST_GREATER_EQUAL
9757
9762
|| kind == ZEND_AST_AND || kind == ZEND_AST_OR
@@ -9766,7 +9771,8 @@ static bool zend_is_allowed_in_const_expr(zend_ast_kind kind) /* {{{ */
9766
9771
|| kind == ZEND_AST_CONST_ENUM_INIT
9767
9772
|| kind == ZEND_AST_NEW || kind == ZEND_AST_ARG_LIST
9768
9773
|| kind == ZEND_AST_NAMED_ARG
9769
- || kind == ZEND_AST_PROP || kind == ZEND_AST_NULLSAFE_PROP ;
9774
+ || kind == ZEND_AST_PROP || kind == ZEND_AST_NULLSAFE_PROP
9775
+ || kind == ZEND_AST_CALLABLE_CONVERT ;
9770
9776
}
9771
9777
/* }}} */
9772
9778
@@ -9930,7 +9936,7 @@ static void zend_compile_const_expr(zend_ast **ast_ptr, void *context) /* {{{ */
9930
9936
return ;
9931
9937
}
9932
9938
9933
- if (!zend_is_allowed_in_const_expr (ast -> kind )) {
9939
+ if (!zend_is_allowed_in_const_expr (ast )) {
9934
9940
zend_error_noreturn (E_COMPILE_ERROR , "Constant expression contains invalid operations" );
9935
9941
}
9936
9942
@@ -10634,6 +10640,20 @@ static void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
10634
10640
zend_eval_const_expr (& ast -> child [0 ]);
10635
10641
zend_eval_const_expr (& ast -> child [1 ]);
10636
10642
return ;
10643
+ case ZEND_AST_CALL :
10644
+ {
10645
+ zend_ast * func_ast ;
10646
+
10647
+ if (ast -> child [1 ]-> kind != ZEND_AST_CALLABLE_CONVERT ) {
10648
+ zend_error_noreturn (E_COMPILE_ERROR , "Constant expression contains invalid operations" );
10649
+ }
10650
+
10651
+ zend_eval_const_expr (& ast -> child [0 ]);
10652
+ func_ast = ast -> child [0 ];
10653
+
10654
+ ZEND_ASSERT (func_ast -> kind == ZEND_AST_ZVAL );
10655
+ return ;
10656
+ }
10637
10657
default :
10638
10658
return ;
10639
10659
}
0 commit comments