Skip to content

Commit ff3f59b

Browse files
committed
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
1 parent b0470d1 commit ff3f59b

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.5.5
44

5+
- Core:
6+
. Fixed bug GH-20672 (Incorrect property_info sizing for locally shadowed
7+
trait properties). (ilutov)
8+
59
- Bz2:
610
. Fix truncation of total output size causing erroneous errors. (ndossche)
711

Zend/tests/gh20672.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
GH-20672: Incorrect property_info sizing for locally shadowed trait properties
3+
--CREDITS--
4+
Jonne Ransijn (yyny)
5+
--FILE--
6+
<?php
7+
8+
trait T {
9+
public static $a;
10+
public static $b;
11+
public static $c;
12+
}
13+
14+
class Base {
15+
public $x;
16+
public $y;
17+
}
18+
19+
class Child extends Base {
20+
public static $a;
21+
public static $b;
22+
public static $c;
23+
public static $d;
24+
25+
use T;
26+
}
27+
28+
?>
29+
===DONE===
30+
--EXPECT--
31+
===DONE===

Zend/zend_inheritance.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,9 +2933,7 @@ static void zend_do_traits_property_binding(zend_class_entry *ce, zend_class_ent
29332933
ZSTR_VAL(prop_name),
29342934
ZSTR_VAL(ce->name));
29352935
}
2936-
if (!(flags & ZEND_ACC_STATIC)) {
2937-
continue;
2938-
}
2936+
continue;
29392937
}
29402938
}
29412939

0 commit comments

Comments
 (0)