From b150eb35d46422d8bec833a34885b43acf488572 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 23 Oct 2025 21:30:17 +0200 Subject: [PATCH] Fix parent hook call with named args Fixes GH-20270 Closes GH-20271 --- NEWS | 1 + Zend/tests/property_hooks/gh20270.phpt | 51 ++++++++++++++++++++++++++ Zend/zend_object_handlers.c | 4 +- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/property_hooks/gh20270.phpt diff --git a/NEWS b/NEWS index acadda0e126..f8f750ef6c9 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ PHP NEWS . Fixed bug GH-19844 (Don't bail when closing resources on shutdown). (ilutov) . Fixed bug GH-20177 (Accessing overridden private property in get_object_vars() triggers assertion error). (ilutov) + . Fixed bug GH-20270 (Broken parent hook call with named arguments). (ilutov) - DOM: . Partially fixed bug GH-16317 (DOM classes do not allow diff --git a/Zend/tests/property_hooks/gh20270.phpt b/Zend/tests/property_hooks/gh20270.phpt new file mode 100644 index 00000000000..173d21990e5 --- /dev/null +++ b/Zend/tests/property_hooks/gh20270.phpt @@ -0,0 +1,51 @@ +--TEST-- +GH-20270: Parent hook call with named arguments +--CREDITS-- +Viet Hoang Luu (@vi3tL0u1s) +--FILE-- + $custom; + } +} + +class B extends A { + public mixed $prop1 { + set { + parent::$prop1::set(value: 42); + parent::$prop1::set(unknown: 43); + } + } + public mixed $prop2 { + set { + parent::$prop2::set(custom: 42); + parent::$prop2::set(value: 43); + } + } +} + +$b = new B(); + +try { + $b->prop1 = 0; +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} +var_dump($b->prop1); + +try { + $b->prop2 = 0; +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} +var_dump($b->prop2); + +?> +--EXPECT-- +Unknown named parameter $unknown +int(42) +Unknown named parameter $value +int(42) diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 67e8664f5a7..c113f65a7a8 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -1783,7 +1783,9 @@ ZEND_API zend_function *zend_get_property_hook_trampoline( const zend_property_info *prop_info, zend_property_hook_kind kind, zend_string *prop_name) { - static const zend_arg_info arg_info[1] = {{0}}; + static const zend_internal_arg_info arg_info[2] = { + { .name = "value" } + }; zend_function *func; if (EXPECTED(EG(trampoline).common.function_name == NULL)) { func = &EG(trampoline);