From 9e5e1005b0b93c36f281907c214e794ca6cdb70a Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Fri, 31 Jul 2026 11:03:33 -0400 Subject: [PATCH] Check object_init_ex() in ReflectionMethod::createFromMethodName() The result was ignored, so calling the factory on an uninstantiable subclass ran on a NULL zend_object: object_init_ex() throws, sets the return value to NULL and reports FAILURE, and Z_REFLECTION_P() then offsets backwards from that NULL. Other object_init_ex() calls in this file already test the result. Closes GH-22978 --- ext/reflection/php_reflection.c | 5 +++- ...nMethod_createFromMethodName_abstract.phpt | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 ext/reflection/tests/ReflectionMethod_createFromMethodName_abstract.phpt diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 65462bb8652f..6346ec16c78a 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3400,7 +3400,10 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_ if (is_constructor) { object = ZEND_THIS; } else { - object_init_ex(return_value, execute_data->This.value.ce ? execute_data->This.value.ce : reflection_method_ptr); + zend_class_entry *called_ce = execute_data->This.value.ce ? execute_data->This.value.ce : reflection_method_ptr; + if (UNEXPECTED(object_init_ex(return_value, called_ce) != SUCCESS)) { + RETURN_THROWS(); + } object = return_value; } intern = Z_REFLECTION_P(object); diff --git a/ext/reflection/tests/ReflectionMethod_createFromMethodName_abstract.phpt b/ext/reflection/tests/ReflectionMethod_createFromMethodName_abstract.phpt new file mode 100644 index 000000000000..c77623176fd4 --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_createFromMethodName_abstract.phpt @@ -0,0 +1,23 @@ +--TEST-- +ReflectionMethod::createFromMethodName() called on an abstract subclass +--FILE-- +getMessage(), PHP_EOL; +} + +var_dump(ReflectionMethod::createFromMethodName('C::a')->name); + +?> +--EXPECT-- +Error: Cannot instantiate abstract class R +string(1) "a"