Skip to content

Commit 622bf8a

Browse files
committed
zend_vm: Use the clone_obj_with handler in ZEND_CLONE
1 parent fff7737 commit 622bf8a

File tree

2 files changed

+83
-25
lines changed

2 files changed

+83
-25
lines changed

Zend/zend_vm_def.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6001,12 +6001,12 @@ ZEND_VM_COLD_CONST_HANDLER(110, ZEND_CLONE, CONST|TMPVAR|UNUSED|THIS|CV, ANY)
60016001
zend_object *zobj;
60026002
zend_class_entry *ce, *scope;
60036003
zend_function *clone;
6004-
zend_object_clone_obj_t clone_call;
60056004

60066005
SAVE_OPLINE();
60076006
obj = GET_OP1_OBJ_ZVAL_PTR_UNDEF(BP_VAR_R);
60086007

6009-
/* ZEND_CLONE also exists as the clone() function and both implementations must be kept in sync. */
6008+
/* ZEND_CLONE also exists as the clone() function and both implementations must be kept in sync.
6009+
* The OPcode intentionally does not support a clone-with property list to keep it simple. */
60106010

60116011
do {
60126012
if (OP1_TYPE == IS_CONST ||
@@ -6033,8 +6033,7 @@ ZEND_VM_COLD_CONST_HANDLER(110, ZEND_CLONE, CONST|TMPVAR|UNUSED|THIS|CV, ANY)
60336033
zobj = Z_OBJ_P(obj);
60346034
ce = zobj->ce;
60356035
clone = ce->clone;
6036-
clone_call = zobj->handlers->clone_obj;
6037-
if (UNEXPECTED(clone_call == NULL)) {
6036+
if (UNEXPECTED(zobj->handlers->clone_obj == NULL)) {
60386037
zend_throw_error(NULL, "Trying to clone an uncloneable object of class %s", ZSTR_VAL(ce->name));
60396038
FREE_OP1();
60406039
ZVAL_UNDEF(EX_VAR(opline->result.var));
@@ -6052,8 +6051,20 @@ ZEND_VM_COLD_CONST_HANDLER(110, ZEND_CLONE, CONST|TMPVAR|UNUSED|THIS|CV, ANY)
60526051
}
60536052
}
60546053

6055-
ZVAL_OBJ(EX_VAR(opline->result.var), clone_call(zobj));
6054+
zend_object *cloned;
6055+
if (zobj->handlers->clone_obj_with) {
6056+
scope = EX(func)->op_array.scope;
6057+
cloned = zobj->handlers->clone_obj_with(zobj, scope, &zend_empty_array);
6058+
} else {
6059+
cloned = zobj->handlers->clone_obj(zobj);
6060+
}
60566061

6062+
ZEND_ASSERT(cloned || EG(exception));
6063+
if (EXPECTED(cloned)) {
6064+
ZVAL_OBJ(EX_VAR(opline->result.var), cloned);
6065+
} else {
6066+
ZVAL_UNDEF(EX_VAR(opline->result.var));
6067+
}
60576068
FREE_OP1();
60586069
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
60596070
}

Zend/zend_vm_execute.h

Lines changed: 67 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)