From 2b270e3231a19cb1091dad10b918a49083048b53 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Fri, 6 Mar 2026 16:37:25 +0100 Subject: [PATCH] Fix property_info sizing for locally shadowed trait properties Previously, static trait properties would always redeclare locally declared static properties to make sure an inherited static property stops sharing a common slot with the parent. This would leave holes in property_info, creating issues for this code: zend_hash_extend(&ce->properties_info, zend_hash_num_elements(&ce->properties_info) + zend_hash_num_elements(&parent_ce->properties_info), 0); where zend_hash_num_elements(&ce->properties_info) + zend_hash_num_elements(&parent_ce->properties_info) is supposed to extend the hash table enough to hold all additional properties coming from parent. However, if ce->properties_info contains holes this might not be enough, given all parent properties are appended at nNumUsed. This could be fixed by further extending the hash table, but we can also avoid the holes in properties_info completely. This is now possible because traits are bound before performing parent class inheritance, declaring the static property and avoiding the defensive copying of these properties. Fixes GH-20672 --- Zend/tests/gh20672.phpt | 29 +++++++++++++++++++++++++++++ Zend/zend_inheritance.c | 4 +--- 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 Zend/tests/gh20672.phpt diff --git a/Zend/tests/gh20672.phpt b/Zend/tests/gh20672.phpt new file mode 100644 index 0000000000000..34d003ba64da3 --- /dev/null +++ b/Zend/tests/gh20672.phpt @@ -0,0 +1,29 @@ +--TEST-- +GH-20672: Incorrect property_info sizing for locally shadowed trait properties +--CREDITS-- +Jonne Ransijn (yyny) +--FILE-- + +--EXPECT-- diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 0b24c2a990c22..d2952094a468c 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -2933,9 +2933,7 @@ static void zend_do_traits_property_binding(zend_class_entry *ce, zend_class_ent ZSTR_VAL(prop_name), ZSTR_VAL(ce->name)); } - if (!(flags & ZEND_ACC_STATIC)) { - continue; - } + continue; } }