Skip to content

RFC: Clone with v2 #18747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Prev Previous commit
zend_objects: Unlock readonly properties after __clone() for clone-…
…with
  • Loading branch information
TimWolla committed Jun 30, 2025
commit b99daf4556f9f01683777e9bc96e7888b67ee660
7 changes: 6 additions & 1 deletion Zend/tests/clone/clone_with_008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ object(Clazz)#%d (2) {
["b"]=>
string(7) "__clone"
}
Error: Cannot modify readonly property Clazz::$b
object(Clazz)#%d (2) {
["a"]=>
string(7) "default"
["b"]=>
string(4) "with"
}
8 changes: 8 additions & 0 deletions Zend/zend_objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ ZEND_API void ZEND_FASTCALL zend_objects_clone_members_ex(zend_object *new_objec
}

if (EXPECTED(!EG(exception)) && zend_hash_num_elements(properties) > 0) {
/* Unlock readonly properties once more. */
if (ZEND_CLASS_HAS_READONLY_PROPS(new_object->ce) && old_object->ce->clone) {
for (uint32_t i = 0; i < new_object->ce->default_properties_count; i++) {
zval* prop = OBJ_PROP_NUM(new_object, i);
Z_PROP_FLAG_P(prop) |= IS_PROP_REINITABLE;
}
}

zend_class_entry *old_scope = EG(fake_scope);

EG(fake_scope) = scope;
Expand Down