@@ -339,6 +339,7 @@ void zend_oparray_context_begin(zend_oparray_context *prev_context, zend_op_arra
339339 CG (context ).try_catch_offset = -1 ;
340340 CG (context ).current_brk_cont = -1 ;
341341 CG (context ).last_brk_cont = 0 ;
342+ CG (has_assigned_to_http_response_header ) = false;
342343 CG (context ).brk_cont_array = NULL ;
343344 CG (context ).labels = NULL ;
344345 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
28672868}
28682869/* }}} */
28692870
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 ) /* {{{ */
28712872{
28722873 zend_ast * name_ast = ast -> child [0 ];
28732874 if (name_ast -> kind == ZEND_AST_ZVAL ) {
@@ -2884,6 +2885,16 @@ static zend_result zend_try_compile_cv(znode *result, zend_ast *ast) /* {{{ */
28842885 return FAILURE ;
28852886 }
28862887
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+
28872898 result -> op_type = IS_CV ;
28882899 result -> u .op .var = lookup_cv (name );
28892900
@@ -2920,6 +2931,14 @@ static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, uint
29202931
29212932 opline -> extended_value = ZEND_FETCH_GLOBAL ;
29222933 } 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+ }
29232942 opline -> extended_value = ZEND_FETCH_LOCAL ;
29242943 }
29252944
@@ -2991,7 +3010,7 @@ static zend_op *zend_compile_simple_var(znode *result, zend_ast *ast, uint32_t t
29913010 result -> op_type = IS_TMP_VAR ;
29923011 }
29933012 return opline ;
2994- } else if (zend_try_compile_cv (result , ast ) == FAILURE ) {
3013+ } else if (zend_try_compile_cv (result , ast , type ) == FAILURE ) {
29953014 return zend_compile_simple_var_no_cv (result , ast , type , delayed );
29963015 }
29973016 return NULL ;
@@ -3417,7 +3436,7 @@ static void zend_compile_expr_with_potential_assign_to_self(
34173436 /* $a[0] = $a should evaluate the right $a first */
34183437 znode cv_node ;
34193438
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 ) {
34213440 zend_compile_simple_var_no_cv (expr_node , expr_ast , BP_VAR_R , 0 );
34223441 } else {
34233442 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) /* {{{ */
34383457 if (is_this_fetch (var_ast )) {
34393458 zend_error_noreturn (E_COMPILE_ERROR , "Cannot re-assign $this" );
34403459 }
3460+ // TODO: Mark assignment to http_response_header?
34413461
34423462 zend_ensure_writable_variable (var_ast );
34433463
@@ -3507,7 +3527,7 @@ static void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
35073527 /* list($a, $b) = $a should evaluate the right $a first */
35083528 znode cv_node ;
35093529
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 ) {
35113531 zend_compile_simple_var_no_cv (& expr_node , expr_ast , BP_VAR_R , 0 );
35123532 } else {
35133533 zend_emit_op_tmp (& expr_node , ZEND_QM_ASSIGN , & cv_node , NULL );
@@ -3822,7 +3842,7 @@ static uint32_t zend_compile_args(
38223842 opcode = ZEND_SEND_VAR_EX ;
38233843 CG (active_op_array )-> fn_flags |= ZEND_ACC_USES_THIS ;
38243844 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 ) {
38263846 opcode = ZEND_SEND_VAR_EX ;
38273847 break ;
38283848 }
@@ -5427,7 +5447,7 @@ static void zend_compile_global_var(zend_ast *ast) /* {{{ */
54275447 // TODO(GLOBALS) Forbid "global $GLOBALS"?
54285448 if (is_this_fetch (var_ast )) {
54295449 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 ) {
54315451 zend_op * opline = zend_emit_op (NULL , ZEND_BIND_GLOBAL , & result , & name_node );
54325452 opline -> extended_value = zend_alloc_cache_slot ();
54335453 } else {
@@ -5553,7 +5573,7 @@ static void zend_compile_unset(zend_ast *ast) /* {{{ */
55535573 case ZEND_AST_VAR :
55545574 if (is_this_fetch (var_ast )) {
55555575 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 ) {
55575577 opline = zend_emit_op (NULL , ZEND_UNSET_CV , & var_node , NULL );
55585578 } else {
55595579 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) /* {{{ */
61166136 if (is_this_fetch (value_ast )) {
61176137 zend_error_noreturn (E_COMPILE_ERROR , "Cannot re-assign $this" );
61186138 } 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 ) {
61206140 SET_NODE (opline -> op2 , & value_node );
61216141 } else {
61226142 opline -> op2_type = IS_VAR ;
@@ -10834,7 +10854,7 @@ static void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */
1083410854 if (is_this_fetch (var_ast )) {
1083510855 opline = zend_emit_op (result , ZEND_ISSET_ISEMPTY_THIS , NULL , NULL );
1083610856 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 ) {
1083810858 opline = zend_emit_op (result , ZEND_ISSET_ISEMPTY_CV , & var_node , NULL );
1083910859 } else {
1084010860 opline = zend_compile_simple_var_no_cv (result , var_ast , BP_VAR_IS , 0 );
0 commit comments