@@ -7714,7 +7714,7 @@ static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array,
7714
7714
zend_string * separator = zend_empty_string ;
7715
7715
zend_string * function = filename ;
7716
7716
char * parens = "" ;
7717
-
7717
+
7718
7718
if (CG (active_op_array ) && CG (active_op_array )-> function_name ) {
7719
7719
if (CG (active_op_array )-> fn_flags & ZEND_ACC_CLOSURE ) {
7720
7720
/* If the parent function is a closure, don't redundantly
@@ -8714,6 +8714,13 @@ static void zend_compile_const_decl(zend_ast *ast) /* {{{ */
8714
8714
value_node .op_type = IS_CONST ;
8715
8715
zend_const_expr_to_zval (value_zv , value_ast_ptr , /* allow_dynamic */ true);
8716
8716
8717
+ if (UNEXPECTED (
8718
+ zend_string_equals_literal_ci (unqualified_name , "exit" )
8719
+ || zend_string_equals_literal_ci (unqualified_name , "die" )
8720
+ )) {
8721
+ zend_throw_error (NULL , "Cannot define constant with name %s" , ZSTR_VAL (unqualified_name ));
8722
+ return ;
8723
+ }
8717
8724
if (zend_get_special_const (ZSTR_VAL (unqualified_name ), ZSTR_LEN (unqualified_name ))) {
8718
8725
zend_error_noreturn (E_COMPILE_ERROR ,
8719
8726
"Cannot redeclare constant '%s'" , ZSTR_VAL (unqualified_name ));
@@ -10009,16 +10016,36 @@ static void zend_compile_const(znode *result, zend_ast *ast) /* {{{ */
10009
10016
10010
10017
bool is_fully_qualified ;
10011
10018
zend_string * orig_name = zend_ast_get_str (name_ast );
10012
- zend_string * resolved_name = zend_resolve_const_name (orig_name , name_ast -> attr , & is_fully_qualified );
10013
10019
10020
+ /* The fake "constants" exit and die must be converted to a function call for exit() */
10014
10021
if (UNEXPECTED (
10015
10022
zend_string_equals_literal_ci (orig_name , "exit" )
10016
10023
|| zend_string_equals_literal_ci (orig_name , "die" )
10017
10024
)) {
10018
- zend_throw_error (NULL , "Cannot define constant with name %s" , ZSTR_VAL (orig_name ));
10025
+ zval * fbc_zv = zend_hash_find (CG (function_table ), ZSTR_KNOWN (ZEND_STR_EXIT ));
10026
+ ZEND_ASSERT (fbc_zv && "exit() function should always exist" );
10027
+ zend_function * fbc = Z_PTR_P (fbc_zv );
10028
+
10029
+ znode name_node ;
10030
+ name_node .op_type = IS_CONST ;
10031
+ ZVAL_STR (& name_node .u .constant , ZSTR_KNOWN (ZEND_STR_EXIT ));
10032
+
10033
+ opline = zend_emit_op (NULL , ZEND_INIT_FCALL , NULL , & name_node );
10034
+ opline -> result .num = zend_alloc_cache_slot ();
10035
+
10036
+ /* Store offset to function from symbol table in op2.extra. */
10037
+ {
10038
+ Bucket * fbc_bucket = (Bucket * )((uintptr_t )fbc_zv - XtOffsetOf (Bucket , val ));
10039
+ Z_EXTRA_P (CT_CONSTANT (opline -> op2 )) = fbc_bucket - CG (function_table )-> arData ;
10040
+ }
10041
+
10042
+ zend_ast * args_list = zend_ast_create_list_0 (ZEND_AST_ARG_LIST );
10043
+ zend_compile_call_common (result , args_list , fbc , ast -> lineno );
10019
10044
return ;
10020
10045
}
10021
10046
10047
+ zend_string * resolved_name = zend_resolve_const_name (orig_name , name_ast -> attr , & is_fully_qualified );
10048
+
10022
10049
if (zend_string_equals_literal (resolved_name , "__COMPILER_HALT_OFFSET__" ) || (name_ast -> attr != ZEND_NAME_RELATIVE && zend_string_equals_literal (orig_name , "__COMPILER_HALT_OFFSET__" ))) {
10023
10050
zend_ast * last = CG (ast );
10024
10051
0 commit comments