@@ -339,6 +339,7 @@ void zend_oparray_context_begin(zend_oparray_context *prev_context, zend_op_arra
339
339
CG (context ).try_catch_offset = -1 ;
340
340
CG (context ).current_brk_cont = -1 ;
341
341
CG (context ).last_brk_cont = 0 ;
342
+ CG (has_assigned_to_http_response_header ) = false;
342
343
CG (context ).brk_cont_array = NULL ;
343
344
CG (context ).labels = NULL ;
344
345
CG (context ).in_jmp_frameless_branch = false;
@@ -2866,7 +2867,7 @@ static void zend_compile_class_ref(znode *result, zend_ast *name_ast, uint32_t f
2866
2867
}
2867
2868
/* }}} */
2868
2869
2869
- static zend_result zend_try_compile_cv (znode * result , zend_ast * ast ) /* {{{ */
2870
+ static zend_result zend_try_compile_cv (znode * result , zend_ast * ast , uint32_t type ) /* {{{ */
2870
2871
{
2871
2872
zend_ast * name_ast = ast -> child [0 ];
2872
2873
if (name_ast -> kind == ZEND_AST_ZVAL ) {
@@ -2883,6 +2884,16 @@ static zend_result zend_try_compile_cv(znode *result, zend_ast *ast) /* {{{ */
2883
2884
return FAILURE ;
2884
2885
}
2885
2886
2887
+ if (zend_string_equals_literal (name , "http_response_header" )) {
2888
+ if (type == BP_VAR_R && !CG (has_assigned_to_http_response_header )) {
2889
+ zend_error (E_DEPRECATED ,
2890
+ "The predefined locally scoped $http_response_header variable is deprecated,"
2891
+ " call http_get_last_response_headers() instead" );
2892
+ } else if (type == BP_VAR_W ) {
2893
+ CG (has_assigned_to_http_response_header ) = true;
2894
+ }
2895
+ }
2896
+
2886
2897
result -> op_type = IS_CV ;
2887
2898
result -> u .op .var = lookup_cv (name );
2888
2899
@@ -2919,6 +2930,14 @@ static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, uint
2919
2930
2920
2931
opline -> extended_value = ZEND_FETCH_GLOBAL ;
2921
2932
} else {
2933
+ // TODO: Have a test case for this?
2934
+ if (name_node .op_type == IS_CONST
2935
+ && type == BP_VAR_R
2936
+ && zend_string_equals_literal (Z_STR (name_node .u .constant ), "http_response_header" )) {
2937
+ zend_error (E_DEPRECATED ,
2938
+ "The predefined locally scoped $http_response_header variable is deprecated,"
2939
+ " call http_get_last_response_headers() instead" );
2940
+ }
2922
2941
opline -> extended_value = ZEND_FETCH_LOCAL ;
2923
2942
}
2924
2943
@@ -2990,7 +3009,7 @@ static zend_op *zend_compile_simple_var(znode *result, zend_ast *ast, uint32_t t
2990
3009
result -> op_type = IS_TMP_VAR ;
2991
3010
}
2992
3011
return opline ;
2993
- } else if (zend_try_compile_cv (result , ast ) == FAILURE ) {
3012
+ } else if (zend_try_compile_cv (result , ast , type ) == FAILURE ) {
2994
3013
return zend_compile_simple_var_no_cv (result , ast , type , delayed );
2995
3014
}
2996
3015
return NULL ;
@@ -3416,7 +3435,7 @@ static void zend_compile_expr_with_potential_assign_to_self(
3416
3435
/* $a[0] = $a should evaluate the right $a first */
3417
3436
znode cv_node ;
3418
3437
3419
- if (zend_try_compile_cv (& cv_node , expr_ast ) == FAILURE ) {
3438
+ if (zend_try_compile_cv (& cv_node , expr_ast , BP_VAR_R ) == FAILURE ) {
3420
3439
zend_compile_simple_var_no_cv (expr_node , expr_ast , BP_VAR_R , 0 );
3421
3440
} else {
3422
3441
zend_emit_op_tmp (expr_node , ZEND_QM_ASSIGN , & cv_node , NULL );
@@ -3437,6 +3456,7 @@ static void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
3437
3456
if (is_this_fetch (var_ast )) {
3438
3457
zend_error_noreturn (E_COMPILE_ERROR , "Cannot re-assign $this" );
3439
3458
}
3459
+ // TODO: Mark assignment to http_response_header?
3440
3460
3441
3461
zend_ensure_writable_variable (var_ast );
3442
3462
@@ -3506,7 +3526,7 @@ static void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
3506
3526
/* list($a, $b) = $a should evaluate the right $a first */
3507
3527
znode cv_node ;
3508
3528
3509
- if (zend_try_compile_cv (& cv_node , expr_ast ) == FAILURE ) {
3529
+ if (zend_try_compile_cv (& cv_node , expr_ast , BP_VAR_R ) == FAILURE ) {
3510
3530
zend_compile_simple_var_no_cv (& expr_node , expr_ast , BP_VAR_R , 0 );
3511
3531
} else {
3512
3532
zend_emit_op_tmp (& expr_node , ZEND_QM_ASSIGN , & cv_node , NULL );
@@ -3821,7 +3841,7 @@ static uint32_t zend_compile_args(
3821
3841
opcode = ZEND_SEND_VAR_EX ;
3822
3842
CG (active_op_array )-> fn_flags |= ZEND_ACC_USES_THIS ;
3823
3843
break ;
3824
- } else if (zend_try_compile_cv (& arg_node , arg ) == SUCCESS ) {
3844
+ } else if (zend_try_compile_cv (& arg_node , arg , BP_VAR_R ) == SUCCESS ) {
3825
3845
opcode = ZEND_SEND_VAR_EX ;
3826
3846
break ;
3827
3847
}
@@ -5424,7 +5444,7 @@ static void zend_compile_global_var(zend_ast *ast) /* {{{ */
5424
5444
// TODO(GLOBALS) Forbid "global $GLOBALS"?
5425
5445
if (is_this_fetch (var_ast )) {
5426
5446
zend_error_noreturn (E_COMPILE_ERROR , "Cannot use $this as global variable" );
5427
- } else if (zend_try_compile_cv (& result , var_ast ) == SUCCESS ) {
5447
+ } else if (zend_try_compile_cv (& result , var_ast , BP_VAR_R ) == SUCCESS ) {
5428
5448
zend_op * opline = zend_emit_op (NULL , ZEND_BIND_GLOBAL , & result , & name_node );
5429
5449
opline -> extended_value = zend_alloc_cache_slot ();
5430
5450
} else {
@@ -5550,7 +5570,7 @@ static void zend_compile_unset(zend_ast *ast) /* {{{ */
5550
5570
case ZEND_AST_VAR :
5551
5571
if (is_this_fetch (var_ast )) {
5552
5572
zend_error_noreturn (E_COMPILE_ERROR , "Cannot unset $this" );
5553
- } else if (zend_try_compile_cv (& var_node , var_ast ) == SUCCESS ) {
5573
+ } else if (zend_try_compile_cv (& var_node , var_ast , BP_VAR_UNSET ) == SUCCESS ) {
5554
5574
opline = zend_emit_op (NULL , ZEND_UNSET_CV , & var_node , NULL );
5555
5575
} else {
5556
5576
opline = zend_compile_simple_var_no_cv (NULL , var_ast , BP_VAR_UNSET , 0 );
@@ -6113,7 +6133,7 @@ static void zend_compile_foreach(zend_ast *ast) /* {{{ */
6113
6133
if (is_this_fetch (value_ast )) {
6114
6134
zend_error_noreturn (E_COMPILE_ERROR , "Cannot re-assign $this" );
6115
6135
} else if (value_ast -> kind == ZEND_AST_VAR &&
6116
- zend_try_compile_cv (& value_node , value_ast ) == SUCCESS ) {
6136
+ zend_try_compile_cv (& value_node , value_ast , BP_VAR_R ) == SUCCESS ) {
6117
6137
SET_NODE (opline -> op2 , & value_node );
6118
6138
} else {
6119
6139
opline -> op2_type = IS_VAR ;
@@ -10801,7 +10821,7 @@ static void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */
10801
10821
if (is_this_fetch (var_ast )) {
10802
10822
opline = zend_emit_op (result , ZEND_ISSET_ISEMPTY_THIS , NULL , NULL );
10803
10823
CG (active_op_array )-> fn_flags |= ZEND_ACC_USES_THIS ;
10804
- } else if (zend_try_compile_cv (& var_node , var_ast ) == SUCCESS ) {
10824
+ } else if (zend_try_compile_cv (& var_node , var_ast , BP_VAR_IS ) == SUCCESS ) {
10805
10825
opline = zend_emit_op (result , ZEND_ISSET_ISEMPTY_CV , & var_node , NULL );
10806
10826
} else {
10807
10827
opline = zend_compile_simple_var_no_cv (result , var_ast , BP_VAR_IS , 0 );
0 commit comments