Skip to content

Commit 490a49d

Browse files
committed
Use COPY_DEREF for DIM_IS and LIST_R as well
Also add an upgrading note for the behavior change, not that we expect anyone to be affected...
1 parent a0a4232 commit 490a49d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

UPGRADING

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ Core:
4444
the following "FOO;" will cause a syntax error. This issue can always be
4545
resolved by choosing an ending label that does not occur within the contents
4646
of the string.
47+
. References returned by array and property accesses are now unwrapped as
48+
part of the access. This means that it is no longer possible to modify the
49+
reference between the access and the use of the accessed value:
50+
51+
$arr = [1];
52+
$ref =& $arr[0];
53+
var_dump($arr[0] + ($arr[0] = 2));
54+
// Previously: int(4), Now: int(3)
55+
56+
This makes the behavior of references and non-references consistent. Please
57+
note that reading and writing a value inside a single expression remains
58+
undefined behavior and may change again in the future.
4759

4860
BCMath:
4961
. All warnings thrown by BCMath functions are now using PHP's error handling.

Zend/zend_execute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
19531953
if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) {
19541954
try_array:
19551955
retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type EXECUTE_DATA_CC);
1956-
ZVAL_COPY(result, retval);
1956+
ZVAL_COPY_DEREF(result, retval);
19571957
return;
19581958
} else if (EXPECTED(Z_TYPE_P(container) == IS_REFERENCE)) {
19591959
container = Z_REFVAL_P(container);

ext/opcache/Optimizer/zend_inference.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ uint32_t zend_array_element_type(zend_op *opline, uint32_t t1)
20602060
}
20612061
if (t1 & MAY_BE_ARRAY_OF_REF) {
20622062
if (opline->opcode == ZEND_FETCH_DIM_R) {
2063-
/* can't be REF because of ZVAL_COPY_DEREF() usage */
2063+
/* can't be REF because of ZVAL_COPY_DEREF() usage */
20642064
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
20652065
} else {
20662066
tmp |= MAY_BE_REF | MAY_BE_RC1 | MAY_BE_RCN;

0 commit comments

Comments
 (0)