Fix property_info sizing for locally shadowed trait properties#21358
Open
iluuu1994 wants to merge 1 commit intophp:PHP-8.5from
Open
Fix property_info sizing for locally shadowed trait properties#21358iluuu1994 wants to merge 1 commit intophp:PHP-8.5from
iluuu1994 wants to merge 1 commit intophp:PHP-8.5from
Conversation
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 phpGH-20672
iluuu1994
commented
Mar 6, 2026
| use T; | ||
| } | ||
|
|
||
| ?> |
Member
Author
There was a problem hiding this comment.
I forgot the ===DONE=== that are usually added to tests with no output. I'll do that before merging.
bwoebi
approved these changes
Mar 6, 2026
Member
Author
Fair point. Any property hitting the two We can replace these branches with asserts on |
Member
|
@iluuu1994 I haven't checked whether they should be indeed dead, but if they are supposed to, then yes, please merge it and replace it by asserts on master. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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, ifce->properties_infocontains 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