1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix incorrect property_info sizing for locally shadowed trait properties

Previously, static trait properties would always redeclare locally declared
static properties to make sure any inherited property would stop 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 by not redeclaring trait properties that
are already declared in the target class. This is now possible because traits
are bound before performing parent class inheritance, so if the property is
already present we know it will separate the property slot.

Fixes GH-20672
Closes GH-21358
This commit is contained in:
Ilija Tovilo
2026-03-06 16:37:25 +01:00
parent b0470d1669
commit ff3f59b5a7
3 changed files with 36 additions and 3 deletions

4
NEWS
View File

@@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.5.5
- Core:
. Fixed bug GH-20672 (Incorrect property_info sizing for locally shadowed
trait properties). (ilutov)
- Bz2:
. Fix truncation of total output size causing erroneous errors. (ndossche)

31
Zend/tests/gh20672.phpt Normal file
View File

@@ -0,0 +1,31 @@
--TEST--
GH-20672: Incorrect property_info sizing for locally shadowed trait properties
--CREDITS--
Jonne Ransijn (yyny)
--FILE--
<?php
trait T {
public static $a;
public static $b;
public static $c;
}
class Base {
public $x;
public $y;
}
class Child extends Base {
public static $a;
public static $b;
public static $c;
public static $d;
use T;
}
?>
===DONE===
--EXPECT--
===DONE===

View File

@@ -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;
}
}