Merge branch 'PHP-7.4' into PHP-8.0

* PHP-7.4:
  Fix leak on foreach by ref assign to property
This commit is contained in:
Nikita Popov 2021-07-01 15:49:34 +02:00
commit 2efee442eb
2 changed files with 16 additions and 7 deletions

View File

@ -0,0 +1,11 @@
--TEST--
Foreach by ref assignment to property
--FILE--
<?php
$obj = new stdClass;
foreach ([0] as &$obj->prop) {
var_dump($obj->prop);
}
?>
--EXPECT--
int(0)

View File

@ -3213,17 +3213,13 @@ void zend_compile_assign_ref(znode *result, zend_ast *ast) /* {{{ */
opline->extended_value &= ~ZEND_FETCH_REF;
opline->extended_value |= flags;
zend_emit_op_data(&source_node);
if (result != NULL) {
*result = target_node;
}
*result = target_node;
} else if (opline && opline->opcode == ZEND_FETCH_STATIC_PROP_W) {
opline->opcode = ZEND_ASSIGN_STATIC_PROP_REF;
opline->extended_value &= ~ZEND_FETCH_REF;
opline->extended_value |= flags;
zend_emit_op_data(&source_node);
if (result != NULL) {
*result = target_node;
}
*result = target_node;
} else {
opline = zend_emit_op(result, ZEND_ASSIGN_REF, &target_node, &source_node);
opline->extended_value = flags;
@ -3233,9 +3229,11 @@ void zend_compile_assign_ref(znode *result, zend_ast *ast) /* {{{ */
static inline void zend_emit_assign_ref_znode(zend_ast *var_ast, znode *value_node) /* {{{ */
{
znode dummy_node;
zend_ast *assign_ast = zend_ast_create(ZEND_AST_ASSIGN_REF, var_ast,
zend_ast_create_znode(value_node));
zend_compile_expr(NULL, assign_ast);
zend_compile_expr(&dummy_node, assign_ast);
zend_do_free(&dummy_node);
}
/* }}} */