@@ -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;
@@ -2867,7 +2868,7 @@ static void zend_compile_class_ref(znode *result, zend_ast *name_ast, uint32_t f
2867
2868
}
2868
2869
/* }}} */
2869
2870
2870
- static zend_result zend_try_compile_cv (znode * result , zend_ast * ast ) /* {{{ */
2871
+ static zend_result zend_try_compile_cv (znode * result , zend_ast * ast , uint32_t type ) /* {{{ */
2871
2872
{
2872
2873
zend_ast * name_ast = ast -> child [0 ];
2873
2874
if (name_ast -> kind == ZEND_AST_ZVAL ) {
@@ -2884,6 +2885,16 @@ static zend_result zend_try_compile_cv(znode *result, zend_ast *ast) /* {{{ */
2884
2885
return FAILURE ;
2885
2886
}
2886
2887
2888
+ if (zend_string_equals_literal (name , "http_response_header" )) {
2889
+ if (type == BP_VAR_R && !CG (has_assigned_to_http_response_header )) {
2890
+ zend_error (E_DEPRECATED ,
2891
+ "The predefined locally scoped $http_response_header variable is deprecated,"
2892
+ " call http_get_last_response_headers() instead" );
2893
+ } else if (type == BP_VAR_W ) {
2894
+ CG (has_assigned_to_http_response_header ) = true;
2895
+ }
2896
+ }
2897
+
2887
2898
result -> op_type = IS_CV ;
2888
2899
result -> u .op .var = lookup_cv (name );
2889
2900
@@ -2920,6 +2931,14 @@ static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, uint
2920
2931
2921
2932
opline -> extended_value = ZEND_FETCH_GLOBAL ;
2922
2933
} else {
2934
+ // TODO: Have a test case for this?
2935
+ if (name_node .op_type == IS_CONST
2936
+ && type == BP_VAR_R
2937
+ && zend_string_equals_literal (Z_STR (name_node .u .constant ), "http_response_header" )) {
2938
+ zend_error (E_DEPRECATED ,
2939
+ "The predefined locally scoped $http_response_header variable is deprecated,"
2940
+ " call http_get_last_response_headers() instead" );
2941
+ }
2923
2942
opline -> extended_value = ZEND_FETCH_LOCAL ;
2924
2943
}
2925
2944
@@ -2991,7 +3010,7 @@ static zend_op *zend_compile_simple_var(znode *result, zend_ast *ast, uint32_t t
2991
3010
result -> op_type = IS_TMP_VAR ;
2992
3011
}
2993
3012
return opline ;
2994
- } else if (zend_try_compile_cv (result , ast ) == FAILURE ) {
3013
+ } else if (zend_try_compile_cv (result , ast , type ) == FAILURE ) {
2995
3014
return zend_compile_simple_var_no_cv (result , ast , type , delayed );
2996
3015
}
2997
3016
return NULL ;
@@ -3417,7 +3436,7 @@ static void zend_compile_expr_with_potential_assign_to_self(
3417
3436
/* $a[0] = $a should evaluate the right $a first */
3418
3437
znode cv_node ;
3419
3438
3420
- if (zend_try_compile_cv (& cv_node , expr_ast ) == FAILURE ) {
3439
+ if (zend_try_compile_cv (& cv_node , expr_ast , BP_VAR_R ) == FAILURE ) {
3421
3440
zend_compile_simple_var_no_cv (expr_node , expr_ast , BP_VAR_R , 0 );
3422
3441
} else {
3423
3442
zend_emit_op_tmp (expr_node , ZEND_QM_ASSIGN , & cv_node , NULL );
@@ -3438,6 +3457,7 @@ static void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
3438
3457
if (is_this_fetch (var_ast )) {
3439
3458
zend_error_noreturn (E_COMPILE_ERROR , "Cannot re-assign $this" );
3440
3459
}
3460
+ // TODO: Mark assignment to http_response_header?
3441
3461
3442
3462
zend_ensure_writable_variable (var_ast );
3443
3463
@@ -3507,7 +3527,7 @@ static void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
3507
3527
/* list($a, $b) = $a should evaluate the right $a first */
3508
3528
znode cv_node ;
3509
3529
3510
- if (zend_try_compile_cv (& cv_node , expr_ast ) == FAILURE ) {
3530
+ if (zend_try_compile_cv (& cv_node , expr_ast , BP_VAR_R ) == FAILURE ) {
3511
3531
zend_compile_simple_var_no_cv (& expr_node , expr_ast , BP_VAR_R , 0 );
3512
3532
} else {
3513
3533
zend_emit_op_tmp (& expr_node , ZEND_QM_ASSIGN , & cv_node , NULL );
@@ -3822,7 +3842,7 @@ static uint32_t zend_compile_args(
3822
3842
opcode = ZEND_SEND_VAR_EX ;
3823
3843
CG (active_op_array )-> fn_flags |= ZEND_ACC_USES_THIS ;
3824
3844
break ;
3825
- } else if (zend_try_compile_cv (& arg_node , arg ) == SUCCESS ) {
3845
+ } else if (zend_try_compile_cv (& arg_node , arg , BP_VAR_R ) == SUCCESS ) {
3826
3846
opcode = ZEND_SEND_VAR_EX ;
3827
3847
break ;
3828
3848
}
@@ -5427,7 +5447,7 @@ static void zend_compile_global_var(zend_ast *ast) /* {{{ */
5427
5447
// TODO(GLOBALS) Forbid "global $GLOBALS"?
5428
5448
if (is_this_fetch (var_ast )) {
5429
5449
zend_error_noreturn (E_COMPILE_ERROR , "Cannot use $this as global variable" );
5430
- } else if (zend_try_compile_cv (& result , var_ast ) == SUCCESS ) {
5450
+ } else if (zend_try_compile_cv (& result , var_ast , BP_VAR_R ) == SUCCESS ) {
5431
5451
zend_op * opline = zend_emit_op (NULL , ZEND_BIND_GLOBAL , & result , & name_node );
5432
5452
opline -> extended_value = zend_alloc_cache_slot ();
5433
5453
} else {
@@ -5553,7 +5573,7 @@ static void zend_compile_unset(zend_ast *ast) /* {{{ */
5553
5573
case ZEND_AST_VAR :
5554
5574
if (is_this_fetch (var_ast )) {
5555
5575
zend_error_noreturn (E_COMPILE_ERROR , "Cannot unset $this" );
5556
- } else if (zend_try_compile_cv (& var_node , var_ast ) == SUCCESS ) {
5576
+ } else if (zend_try_compile_cv (& var_node , var_ast , BP_VAR_UNSET ) == SUCCESS ) {
5557
5577
opline = zend_emit_op (NULL , ZEND_UNSET_CV , & var_node , NULL );
5558
5578
} else {
5559
5579
opline = zend_compile_simple_var_no_cv (NULL , var_ast , BP_VAR_UNSET , 0 );
@@ -6116,7 +6136,7 @@ static void zend_compile_foreach(zend_ast *ast) /* {{{ */
6116
6136
if (is_this_fetch (value_ast )) {
6117
6137
zend_error_noreturn (E_COMPILE_ERROR , "Cannot re-assign $this" );
6118
6138
} else if (value_ast -> kind == ZEND_AST_VAR &&
6119
- zend_try_compile_cv (& value_node , value_ast ) == SUCCESS ) {
6139
+ zend_try_compile_cv (& value_node , value_ast , BP_VAR_R ) == SUCCESS ) {
6120
6140
SET_NODE (opline -> op2 , & value_node );
6121
6141
} else {
6122
6142
opline -> op2_type = IS_VAR ;
@@ -10834,7 +10854,7 @@ static void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */
10834
10854
if (is_this_fetch (var_ast )) {
10835
10855
opline = zend_emit_op (result , ZEND_ISSET_ISEMPTY_THIS , NULL , NULL );
10836
10856
CG (active_op_array )-> fn_flags |= ZEND_ACC_USES_THIS ;
10837
- } else if (zend_try_compile_cv (& var_node , var_ast ) == SUCCESS ) {
10857
+ } else if (zend_try_compile_cv (& var_node , var_ast , BP_VAR_IS ) == SUCCESS ) {
10838
10858
opline = zend_emit_op (result , ZEND_ISSET_ISEMPTY_CV , & var_node , NULL );
10839
10859
} else {
10840
10860
opline = zend_compile_simple_var_no_cv (result , var_ast , BP_VAR_IS , 0 );
0 commit comments