Skip to content

Remove dead code from zend_declare_typed_property()#21391

Draft
iluuu1994 wants to merge 3 commits intophp:masterfrom
iluuu1994:zend_declare_typed_property-dead-code
Draft

Remove dead code from zend_declare_typed_property()#21391
iluuu1994 wants to merge 3 commits intophp:masterfrom
iluuu1994:zend_declare_typed_property-dead-code

Conversation

@iluuu1994
Copy link
Member

Since GH-15878, trait properties are bound before linking the parent class. Since GH-21358, trait properties don't redeclare locally declared properties. With these two changes, declared properties are never redeclared, and as such we can remove this case from zend_declare_typed_property().

Since phpGH-15878, trait properties are bound before linking the parent class.
Since phpGH-21358, trait properties don't redeclare locally declared properties.
With these two changes, declared properties are never redeclared, and as such we
can remove this case from zend_declare_typed_property().
@iluuu1994 iluuu1994 requested a review from dstogov as a code owner March 9, 2026 13:02
@iluuu1994 iluuu1994 marked this pull request as draft March 9, 2026 13:13
@Girgias
Copy link
Member

Girgias commented Mar 9, 2026

Would this need to be reintroduced if we want to resolve self types for trait methods?

@iluuu1994
Copy link
Member Author

Would this need to be reintroduced if we want to resolve self types for trait methods?

I don't know exactly what you mean, but FWIU your case doesn't involve properties, so probably not?

@Girgias
Copy link
Member

Girgias commented Mar 9, 2026

Would this need to be reintroduced if we want to resolve self types for trait methods?

I don't know exactly what you mean, but FWIU your case doesn't involve properties, so probably not?

Possibly, but for clarity I meant that if a trait is declared as such:

trait T {
    public self $v;
}

class C {
    use T;
}

if this affects "redeclaring" the type of $v from the trait from self to C.

@iluuu1994
Copy link
Member Author

if this affects "redeclaring" the type of $v from the trait from self to C.

No redeclaration happens in this case. So inferring self for the declaration shouldn't cause any issues.

Comment on lines +3678 to +3686
if ($this->type === "class" && isset($this->extends[0])) {
$parent = "class_entry_" . str_replace("\\", "_", $this->extends[0]->toString());
$code .= "\n\tzend_do_inheritance_ex(class_entry, $parent, 0);";
}
$code .= "\n\tzend_build_properties_info_table(class_entry);\n";

if (!empty($implements)) {
$code .= "\tzend_class_implements(class_entry, " . count($implements) . ", " . implode(", ", $implements) . ");\n";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to emit preprocessor checks on PHP_VERSION_ID for this or is the new output compatible with earlier PHP versions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically compatible, though I think it's a good point that the previous behavior should likely be maintained for older PHP versions when regenerating stubs. I'll ship this in a different PR entirely. Also still need to check why zend_test fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants