PHP must not create circular arrays when element is assigned by value.

This commit is contained in:
Dmitry Stogov 2017-10-12 16:23:45 +03:00
parent eb4342eb14
commit edc7c8ccfa
2 changed files with 21 additions and 10 deletions

View File

@ -14,20 +14,19 @@ $a[0][0] = $a;
debug_zval_dump($a);
?>
--EXPECTF--
array(1) refcount(%d){
array(1) refcount(2){
[0]=>
array(1) refcount(%d){
[0]=>
*RECURSION*
array(0) refcount(1){
}
}
array(1) refcount(%d){
array(1) refcount(2){
[0]=>
array(1) refcount(%d){
array(1) refcount(1){
[0]=>
array(1) refcount(%d){
array(1) refcount(1){
[0]=>
*RECURSION*
array(0) refcount(1){
}
}
}
}

View File

@ -3000,7 +3000,13 @@ void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
if (zend_is_assign_to_self(var_ast, expr_ast)
&& !is_this_fetch(expr_ast)) {
/* $a[0] = $a should evaluate the right $a first */
zend_compile_simple_var_no_cv(&expr_node, expr_ast, BP_VAR_R, 0);
znode cv_node;
if (zend_try_compile_cv(&cv_node, expr_ast) == FAILURE) {
zend_compile_simple_var_no_cv(&expr_node, expr_ast, BP_VAR_R, 0);
} else {
zend_emit_op(&expr_node, ZEND_QM_ASSIGN, &cv_node, NULL);
}
} else {
zend_compile_expr(&expr_node, expr_ast);
}
@ -3023,7 +3029,13 @@ void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
case ZEND_AST_ARRAY:
if (zend_list_has_assign_to_self(var_ast, expr_ast)) {
/* list($a, $b) = $a should evaluate the right $a first */
zend_compile_simple_var_no_cv(&expr_node, expr_ast, BP_VAR_R, 0);
znode cv_node;
if (zend_try_compile_cv(&cv_node, expr_ast) == FAILURE) {
zend_compile_simple_var_no_cv(&expr_node, expr_ast, BP_VAR_R, 0);
} else {
zend_emit_op(&expr_node, ZEND_QM_ASSIGN, &cv_node, NULL);
}
} else {
zend_compile_expr(&expr_node, expr_ast);
}