From 07e5f6fc3d92cb5cc3e91a2bee83fc442ac6d30c Mon Sep 17 00:00:00 2001 From: DanielEScherzer Date: Fri, 14 Feb 2025 07:50:33 -0800 Subject: [PATCH] `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`. --- ext/reflection/php_reflection.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index fcaa5c270e2..6d5b9d71c27 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4828,24 +4828,19 @@ ZEND_METHOD(ReflectionClass, isCloneable) if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS | ZEND_ACC_ENUM)) { RETURN_FALSE; } + if (ce->clone) { + RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC); + } if (!Z_ISUNDEF(intern->obj)) { - if (ce->clone) { - RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC); - } else { - RETURN_BOOL(Z_OBJ_HANDLER(intern->obj, clone_obj) != NULL); - } + RETURN_BOOL(Z_OBJ_HANDLER(intern->obj, clone_obj) != NULL); } else { - if (ce->clone) { - RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC); - } else { - if (UNEXPECTED(object_init_ex(&obj, ce) != SUCCESS)) { - return; - } - /* We're not calling the constructor, so don't call the destructor either. */ - zend_object_store_ctor_failed(Z_OBJ(obj)); - RETVAL_BOOL(Z_OBJ_HANDLER(obj, clone_obj) != NULL); - zval_ptr_dtor(&obj); + if (UNEXPECTED(object_init_ex(&obj, ce) != SUCCESS)) { + return; } + /* We're not calling the constructor, so don't call the destructor either. */ + zend_object_store_ctor_failed(Z_OBJ(obj)); + RETVAL_BOOL(Z_OBJ_HANDLER(obj, clone_obj) != NULL); + zval_ptr_dtor(&obj); } } /* }}} */