Skip to content

Commit 55122c3

Browse files
committed
Return copy for object W/RW/UNSET
There was a test checking this, but it didn't actually have the correct result, duh.
1 parent 90d6ce1 commit 55122c3

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Zend/tests/readonly_props/readonly_containing_object.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ object(stdClass)#2 (1) {
5151
["foo"]=>
5252
int(3)
5353
}
54-
object(stdClass)#5 (0) {
54+
object(stdClass)#2 (1) {
55+
["foo"]=>
56+
int(3)
5557
}
56-
object(ArrayObject)#4 (1) {
58+
object(ArrayObject)#7 (1) {
5759
["storage":"ArrayObject":private]=>
5860
array(1) {
5961
[0]=>

Zend/zend_object_handlers.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,13 @@ ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int
588588
if (EXPECTED(Z_TYPE_P(retval) != IS_UNDEF)) {
589589
if (prop_info && UNEXPECTED(prop_info->flags & ZEND_ACC_READONLY)
590590
&& (type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET)) {
591-
if (Z_TYPE_P(retval) != IS_OBJECT) {
591+
if (Z_TYPE_P(retval) == IS_OBJECT) {
592+
/* For objects, R/RW/UNSET fetch modes might not actually modify object.
593+
* Similar as with magic __get() allow them, but return the value as a copy
594+
* to make sure no actual modification is possible. */
595+
ZVAL_COPY(rv, retval);
596+
retval = rv;
597+
} else {
592598
zend_readonly_property_modification_error(prop_info);
593599
retval = &EG(uninitialized_zval);
594600
}

0 commit comments

Comments
 (0)