Skip to content

Commit 1a94b15

Browse files
committed
zend_vm: Use the clone_obj_with handler in ZEND_CLONE
1 parent 1bb245a commit 1a94b15

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));
@@ -6054,8 +6053,20 @@ ZEND_VM_COLD_CONST_HANDLER(110, ZEND_CLONE, CONST|TMPVAR|UNUSED|THIS|CV, ANY)
60546053
}
60556054
}
60566055

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

6064+
ZEND_ASSERT(cloned || EG(exception));
6065+
if (EXPECTED(cloned)) {
6066+
ZVAL_OBJ(EX_VAR(opline->result.var), cloned);
6067+
} else {
6068+
ZVAL_UNDEF(EX_VAR(opline->result.var));
6069+
}
60596070
FREE_OP1();
60606071
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
60616072
}

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)