Skip to content

Commit 05ca575

Browse files
committed
Fixed reference support (references to references are not allowed)
1 parent e430948 commit 05ca575

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

Zend/zend_object_handlers.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,24 @@ ZEND_API void zend_std_write_property(zval *object, zval *member, zval *value, v
593593
ZVAL_COPY_VALUE(&garbage, Z_REFVAL_P(variable_ptr)); /* old value should be destroyed */
594594

595595
/* To check: can't *variable_ptr be some system variable like error_zval here? */
596-
ZVAL_COPY_VALUE(Z_REFVAL_P(variable_ptr), value);
597-
if (Z_REFCOUNTED_P(value) && Z_REFCOUNT_P(value) > 0) {
598-
zval_copy_ctor(Z_REFVAL_P(variable_ptr));
596+
if (UNEXPECTED(Z_REFCOUNTED_P(value))) {
597+
if (EXPECTED(!Z_ISREF_P(value))) {
598+
Z_ADDREF_P(value);
599+
} else {
600+
if (Z_REFCOUNT_P(value) == 1) {
601+
ZVAL_UNREF(value);
602+
} else {
603+
value = Z_REFVAL_P(value);
604+
}
605+
if (Z_REFCOUNTED_P(value)) {
606+
if (UNEXPECTED(Z_REFVAL_P(variable_ptr) == value)) {
607+
goto exit;
608+
}
609+
Z_ADDREF_P(value);
610+
}
611+
}
599612
}
613+
ZVAL_COPY_VALUE(Z_REFVAL_P(variable_ptr), value);
600614
zval_ptr_dtor(&garbage);
601615
} else {
602616
zval garbage;

0 commit comments

Comments
 (0)