Skip to content

Commit c2e48fc

Browse files
committed
Review fixes
1 parent 217f83d commit c2e48fc

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Readonly property can be reset once during cloning even after a type error
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public readonly int $bar;
8+
9+
public function __clone()
10+
{
11+
try {
12+
$this->bar = "foo";
13+
} catch (Error $e) {
14+
echo $e->getMessage() . "\n";
15+
}
16+
17+
$this->bar = 1;
18+
}
19+
}
20+
21+
$foo = new Foo();
22+
23+
var_dump(clone $foo);
24+
var_dump(clone $foo);
25+
26+
?>
27+
--EXPECTF--
28+
Cannot assign string to property Foo::$bar of type int
29+
object(Foo)#%d (%d) {
30+
["bar"]=>
31+
int(1)
32+
}
33+
Cannot assign string to property Foo::$bar of type int
34+
object(Foo)#%d (%d) {
35+
["bar"]=>
36+
int(1)
37+
}

Zend/zend_objects.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ ZEND_API void ZEND_FASTCALL zend_objects_clone_members(zend_object *new_object,
204204
ZVAL_COPY_VALUE_PROP(dst, src);
205205
zval_add_ref(dst);
206206
if (has_clone_method) {
207+
/* Unconditionally add the IS_PROP_REINITABLE flag to avoid a potential cache miss of property_info */
207208
Z_PROP_FLAG_P(dst) |= IS_PROP_REINITABLE;
208209
}
209210

@@ -252,6 +253,7 @@ ZEND_API void ZEND_FASTCALL zend_objects_clone_members(zend_object *new_object,
252253
zval_add_ref(&new_prop);
253254
}
254255
if (has_clone_method) {
256+
/* Unconditionally add the IS_PROP_REINITABLE flag to avoid a potential cache miss of property_info */
255257
Z_PROP_FLAG_P(&new_prop) |= IS_PROP_REINITABLE;
256258
}
257259
if (EXPECTED(key)) {
@@ -268,11 +270,9 @@ ZEND_API void ZEND_FASTCALL zend_objects_clone_members(zend_object *new_object,
268270

269271
if (ZEND_CLASS_HAS_READONLY_PROPS(new_object->ce)) {
270272
for (uint32_t i = 0; i < new_object->ce->default_properties_count; i++) {
271-
zend_property_info *prop_info = new_object->ce->properties_info_table[i];
272-
if (prop_info && (prop_info->flags & ZEND_ACC_READONLY)) {
273-
zval * prop = OBJ_PROP_NUM(new_object, i);
274-
Z_PROP_FLAG_P(prop) &= ~IS_PROP_REINITABLE;
275-
}
273+
zval* prop = OBJ_PROP_NUM(new_object, i);
274+
/* Unconditionally remove the IS_PROP_REINITABLE flag to avoid a potential cache miss of property_info */
275+
Z_PROP_FLAG_P(prop) &= ~IS_PROP_REINITABLE;
276276
}
277277
}
278278

0 commit comments

Comments
 (0)