mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
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
32 lines
428 B
PHP
32 lines
428 B
PHP
--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===
|