From b6d7c011b87437f4489cb2258bb2166cdc308a71 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Mon, 19 Aug 2024 17:39:31 +0200 Subject: [PATCH] Fix virtual properties in get_class_vars() (GH-15494) Fixes GH-15456 --- NEWS | 2 ++ Zend/tests/property_hooks/gh15456.phpt | 20 ++++++++++++++++++++ Zend/zend_builtin_functions.c | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/property_hooks/gh15456.phpt diff --git a/NEWS b/NEWS index 54018fcab1f..090a43b11c8 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,8 @@ PHP NEWS . Fixed bug GH-15419 (Missing readonly+hook incompatibility check for readonly classes). (ilutov) . Fixed bug GH-15187 (Various hooked object iterator issues). (ilutov) + . Fixed bug GH-15456 (Crash in get_class_vars() on virtual properties). + (ilutov) 15 Aug 2024, PHP 8.4.0beta3 diff --git a/Zend/tests/property_hooks/gh15456.phpt b/Zend/tests/property_hooks/gh15456.phpt new file mode 100644 index 00000000000..10a7dbbfb04 --- /dev/null +++ b/Zend/tests/property_hooks/gh15456.phpt @@ -0,0 +1,20 @@ +--TEST-- +GH-15456: Crash in get_class_vars() on virtual properties +--FILE-- + $this->b * 2; } + public $c { get => 42; } +} +var_dump(get_class_vars(C::class)); + +?> +--EXPECT-- +array(2) { + ["a"]=> + int(42) + ["b"]=> + int(42) +} diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 245552d0946..377bc23c46b 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -724,7 +724,8 @@ static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, bool s if (((prop_info->flags & ZEND_ACC_PROTECTED) && !zend_check_protected(prop_info->ce, scope)) || ((prop_info->flags & ZEND_ACC_PRIVATE) && - prop_info->ce != scope)) { + prop_info->ce != scope) || + (prop_info->flags & ZEND_ACC_VIRTUAL)) { continue; } prop = NULL;