Skip to content

Commit 9420cc9

Browse files
committed
zend_vm: Use the clone_obj_with handler in ZEND_CLONE
1 parent bce5549 commit 9420cc9

File tree

2 files changed

+88
-25
lines changed

2 files changed

+88
-25
lines changed

Zend/zend_vm_def.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6001,12 +6001,13 @@ 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.
6010+
*/
60106011

60116012
do {
60126013
if (OP1_TYPE == IS_CONST ||
@@ -6033,8 +6034,7 @@ ZEND_VM_COLD_CONST_HANDLER(110, ZEND_CLONE, CONST|TMPVAR|UNUSED|THIS|CV, ANY)
60336034
zobj = Z_OBJ_P(obj);
60346035
ce = zobj->ce;
60356036
clone = ce->clone;
6036-
clone_call = zobj->handlers->clone_obj;
6037-
if (UNEXPECTED(clone_call == NULL)) {
6037+
if (UNEXPECTED(zobj->handlers->clone_obj == NULL)) {
60386038
zend_throw_error(NULL, "Trying to clone an uncloneable object of class %s", ZSTR_VAL(ce->name));
60396039
FREE_OP1();
60406040
ZVAL_UNDEF(EX_VAR(opline->result.var));
@@ -6054,8 +6054,20 @@ ZEND_VM_COLD_CONST_HANDLER(110, ZEND_CLONE, CONST|TMPVAR|UNUSED|THIS|CV, ANY)
60546054
}
60556055
}
60566056

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

6065+
ZEND_ASSERT(cloned || EG(exception));
6066+
if (EXPECTED(cloned)) {
6067+
ZVAL_OBJ(EX_VAR(opline->result.var), cloned);
6068+
} else {
6069+
ZVAL_UNDEF(EX_VAR(opline->result.var));
6070+
}
60596071
FREE_OP1();
60606072
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
60616073
}

Zend/zend_vm_execute.h

Lines changed: 71 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)