1
0
mirror of https://github.com/php/php-src.git synced 2026-03-31 12:42:29 +02:00

Merge branch 'PHP-7.0' into PHP-7.1

* PHP-7.0:
  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:14:37 +03:00
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

@@ -1642,6 +1642,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;
@@ -1660,6 +1664,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;
}
}