Fixed behavior of failing compound assignments (they shouldn't change the source value when exception thrown during type converion).

This commit is contained in:
Dmitry Stogov 2016-12-02 15:13:55 +03:00
parent dbf39cddd9
commit 2b70d44b57
2 changed files with 28 additions and 0 deletions

View File

@ -1,5 +1,7 @@
--TEST--
Behavior of failing compound assignment
--INI--
opcache.optimization_level=0
--FILE--
<?php
@ -17,8 +19,23 @@ try {
$a = 1;
$a <<= -1;
} catch (Error $e) { var_dump($a); }
set_error_handler(function() { throw new Exception; });
try {
$a = [];
$a .= "foo";
} catch (Throwable $e) { var_dump($a); }
try {
$a = "foo";
$a .= [];
} catch (Throwable $e) { var_dump($a); }
?>
--EXPECT--
int(1)
int(1)
int(1)
array(0) {
}
string(3) "foo"

View File

@ -1628,6 +1628,10 @@ ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) /
ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_CONCAT, concat_function);
use_copy1 = zend_make_printable_zval(op1, &op1_copy);
if (use_copy1) {
if (UNEXPECTED(EG(exception))) {
zval_dtor(&op1_copy);
return FAILURE;
}
if (result == op1) {
if (UNEXPECTED(op1 == op2)) {
op2 = &op1_copy;
@ -1646,6 +1650,13 @@ ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) /
ZEND_TRY_BINARY_OP2_OBJECT_OPERATION(ZEND_CONCAT);
use_copy2 = zend_make_printable_zval(op2, &op2_copy);
if (use_copy2) {
if (UNEXPECTED(EG(exception))) {
if (UNEXPECTED(use_copy1)) {
zval_dtor(op1);
}
zval_dtor(&op2_copy);
return FAILURE;
}
op2 = &op2_copy;
}
}