@@ -2313,6 +2313,13 @@ static bool zend_ast_is_short_circuited(const zend_ast *ast)
23132313 }
23142314}
23152315
2316+ static void zend_assert_not_short_circuited (const zend_ast * ast )
2317+ {
2318+ if (zend_ast_is_short_circuited (ast )) {
2319+ zend_error_noreturn (E_COMPILE_ERROR , "Cannot take reference of a nullsafe chain" );
2320+ }
2321+ }
2322+
23162323/* Mark nodes that are an inner part of a short-circuiting chain.
23172324 * We should not perform a "commit" on them, as it will be performed by the outer-most node.
23182325 * We do this to avoid passing down an argument in various compile functions. */
@@ -3301,9 +3308,8 @@ static void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
33013308 if (!zend_is_variable_or_call (expr_ast )) {
33023309 zend_error_noreturn (E_COMPILE_ERROR ,
33033310 "Cannot assign reference to non referenceable value" );
3304- } else if (zend_ast_is_short_circuited (expr_ast )) {
3305- zend_error_noreturn (E_COMPILE_ERROR ,
3306- "Cannot take reference of a nullsafe chain" );
3311+ } else {
3312+ zend_assert_not_short_circuited (expr_ast );
33073313 }
33083314
33093315 zend_compile_var (& expr_node , expr_ast , BP_VAR_W , 1 );
@@ -3345,9 +3351,7 @@ static void zend_compile_assign_ref(znode *result, zend_ast *ast) /* {{{ */
33453351 zend_error_noreturn (E_COMPILE_ERROR , "Cannot re-assign $this" );
33463352 }
33473353 zend_ensure_writable_variable (target_ast );
3348- if (zend_ast_is_short_circuited (source_ast )) {
3349- zend_error_noreturn (E_COMPILE_ERROR , "Cannot take reference of a nullsafe chain" );
3350- }
3354+ zend_assert_not_short_circuited (source_ast );
33513355 if (is_globals_fetch (source_ast )) {
33523356 zend_error_noreturn (E_COMPILE_ERROR , "Cannot acquire reference to $GLOBALS" );
33533357 }
@@ -5023,10 +5027,7 @@ static void zend_compile_return(zend_ast *ast) /* {{{ */
50235027 expr_node .op_type = IS_CONST ;
50245028 ZVAL_NULL (& expr_node .u .constant );
50255029 } else if (by_ref && zend_is_variable (expr_ast )) {
5026- if (zend_ast_is_short_circuited (expr_ast )) {
5027- zend_error_noreturn (E_COMPILE_ERROR , "Cannot take reference of a nullsafe chain" );
5028- }
5029-
5030+ zend_assert_not_short_circuited (expr_ast );
50305031 zend_compile_var (& expr_node , expr_ast , BP_VAR_W , 1 );
50315032 } else {
50325033 zend_compile_expr (& expr_node , expr_ast );
@@ -9326,6 +9327,7 @@ static void zend_compile_yield(znode *result, zend_ast *ast) /* {{{ */
93269327
93279328 if (value_ast ) {
93289329 if (returns_by_ref && zend_is_variable (value_ast )) {
9330+ zend_assert_not_short_circuited (value_ast );
93299331 zend_compile_var (& value_node , value_ast , BP_VAR_W , 1 );
93309332 } else {
93319333 zend_compile_expr (& value_node , value_ast );
0 commit comments