More fixes for array/object casts with temporary variables

This commit is contained in:
Nikita Popov 2014-10-13 15:19:23 +02:00
parent e62edf2e58
commit 5d94ba6ec3
3 changed files with 70 additions and 57 deletions

View File

@ -0,0 +1,47 @@
--TEST--
(object) (array) and (array) (object) casts
--FILE--
<?php
$arr = [1, 2, 3];
var_dump((object) (array) $arr);
var_dump($arr);
$obj = (object) [1, 2, 3];
var_dump((array) (object) $obj);
var_dump($obj);
?>
--EXPECT--
object(stdClass)#1 (3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
object(stdClass)#1 (3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}

View File

@ -4058,15 +4058,13 @@ ZEND_VM_HANDLER(21, ZEND_CAST, CONST|TMP|VAR|CV, ANY)
if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) {
zval_copy_ctor_func(expr);
}
} else if (OP1_TYPE != IS_TMP_VAR) {
} else {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
}
}
} else {
ZVAL_COPY_VALUE(result, expr);
if (OP1_TYPE != IS_TMP_VAR) {
zval_opt_copy_ctor(result);
}
Z_ADDREF_P(result);
convert_to_array(result);
}
} else {
@ -4078,23 +4076,18 @@ ZEND_VM_HANDLER(21, ZEND_CAST, CONST|TMP|VAR|CV, ANY)
if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) {
zval_copy_ctor_func(expr);
}
} else if (OP1_TYPE != IS_TMP_VAR) {
} else {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
}
}
} else {
ZVAL_COPY_VALUE(result, expr);
if (OP1_TYPE != IS_TMP_VAR) {
zval_opt_copy_ctor(result);
}
zval_opt_copy_ctor(result);
convert_to_object(result);
}
}
FREE_OP1_IF_VAR();
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
FREE_OP1();
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();

View File

@ -2893,15 +2893,13 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) {
zval_copy_ctor_func(expr);
}
} else if (IS_CONST != IS_TMP_VAR) {
} else {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
}
}
} else {
ZVAL_COPY_VALUE(result, expr);
if (IS_CONST != IS_TMP_VAR) {
zval_opt_copy_ctor(result);
}
Z_ADDREF_P(result);
convert_to_array(result);
}
} else {
@ -2913,21 +2911,16 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) {
zval_copy_ctor_func(expr);
}
} else if (IS_CONST != IS_TMP_VAR) {
} else {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
}
}
} else {
ZVAL_COPY_VALUE(result, expr);
if (IS_CONST != IS_TMP_VAR) {
zval_opt_copy_ctor(result);
}
zval_opt_copy_ctor(result);
convert_to_object(result);
}
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
CHECK_EXCEPTION();
@ -9709,15 +9702,13 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) {
zval_copy_ctor_func(expr);
}
} else if (IS_TMP_VAR != IS_TMP_VAR) {
} else {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
}
}
} else {
ZVAL_COPY_VALUE(result, expr);
if (IS_TMP_VAR != IS_TMP_VAR) {
zval_opt_copy_ctor(result);
}
Z_ADDREF_P(result);
convert_to_array(result);
}
} else {
@ -9729,22 +9720,18 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) {
zval_copy_ctor_func(expr);
}
} else if (IS_TMP_VAR != IS_TMP_VAR) {
} else {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
}
}
} else {
ZVAL_COPY_VALUE(result, expr);
if (IS_TMP_VAR != IS_TMP_VAR) {
zval_opt_copy_ctor(result);
}
zval_opt_copy_ctor(result);
convert_to_object(result);
}
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
zval_ptr_dtor_nogc(free_op1.var);
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
@ -16430,15 +16417,13 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) {
zval_copy_ctor_func(expr);
}
} else if (IS_VAR != IS_TMP_VAR) {
} else {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
}
}
} else {
ZVAL_COPY_VALUE(result, expr);
if (IS_VAR != IS_TMP_VAR) {
zval_opt_copy_ctor(result);
}
Z_ADDREF_P(result);
convert_to_array(result);
}
} else {
@ -16450,23 +16435,18 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) {
zval_copy_ctor_func(expr);
}
} else if (IS_VAR != IS_TMP_VAR) {
} else {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
}
}
} else {
ZVAL_COPY_VALUE(result, expr);
if (IS_VAR != IS_TMP_VAR) {
zval_opt_copy_ctor(result);
}
zval_opt_copy_ctor(result);
convert_to_object(result);
}
}
zval_ptr_dtor_nogc(free_op1.var);
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
zval_ptr_dtor_nogc(free_op1.var);
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
@ -34079,15 +34059,13 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) {
zval_copy_ctor_func(expr);
}
} else if (IS_CV != IS_TMP_VAR) {
} else {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
}
}
} else {
ZVAL_COPY_VALUE(result, expr);
if (IS_CV != IS_TMP_VAR) {
zval_opt_copy_ctor(result);
}
Z_ADDREF_P(result);
convert_to_array(result);
}
} else {
@ -34099,21 +34077,16 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) {
zval_copy_ctor_func(expr);
}
} else if (IS_CV != IS_TMP_VAR) {
} else {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
}
}
} else {
ZVAL_COPY_VALUE(result, expr);
if (IS_CV != IS_TMP_VAR) {
zval_opt_copy_ctor(result);
}
zval_opt_copy_ctor(result);
convert_to_object(result);
}
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
CHECK_EXCEPTION();