Skip to content

Commit 07e5f6f

Browse files
ReflectionClass::isCloneable(): reduce duplication (GH-17795)
When the `zend_class_entry` has a `zend_function` entry for `clone`, the logic is the same regardless of if the `reflection_object` entry has an object or not; the determination is based solely on the flags of the `zend_function`.
1 parent 77d7486 commit 07e5f6f

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

ext/reflection/php_reflection.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4828,24 +4828,19 @@ ZEND_METHOD(ReflectionClass, isCloneable)
48284828
if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS | ZEND_ACC_ENUM)) {
48294829
RETURN_FALSE;
48304830
}
4831+
if (ce->clone) {
4832+
RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC);
4833+
}
48314834
if (!Z_ISUNDEF(intern->obj)) {
4832-
if (ce->clone) {
4833-
RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC);
4834-
} else {
4835-
RETURN_BOOL(Z_OBJ_HANDLER(intern->obj, clone_obj) != NULL);
4836-
}
4835+
RETURN_BOOL(Z_OBJ_HANDLER(intern->obj, clone_obj) != NULL);
48374836
} else {
4838-
if (ce->clone) {
4839-
RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC);
4840-
} else {
4841-
if (UNEXPECTED(object_init_ex(&obj, ce) != SUCCESS)) {
4842-
return;
4843-
}
4844-
/* We're not calling the constructor, so don't call the destructor either. */
4845-
zend_object_store_ctor_failed(Z_OBJ(obj));
4846-
RETVAL_BOOL(Z_OBJ_HANDLER(obj, clone_obj) != NULL);
4847-
zval_ptr_dtor(&obj);
4837+
if (UNEXPECTED(object_init_ex(&obj, ce) != SUCCESS)) {
4838+
return;
48484839
}
4840+
/* We're not calling the constructor, so don't call the destructor either. */
4841+
zend_object_store_ctor_failed(Z_OBJ(obj));
4842+
RETVAL_BOOL(Z_OBJ_HANDLER(obj, clone_obj) != NULL);
4843+
zval_ptr_dtor(&obj);
48494844
}
48504845
}
48514846
/* }}} */

0 commit comments

Comments
 (0)