Skip to content

Add support for PHP 8.4 interface properties#4087

Merged
jaapio merged 8 commits intophpDocumentor:masterfrom
lacatoire:feat/interface-properties
Apr 14, 2026
Merged

Add support for PHP 8.4 interface properties#4087
jaapio merged 8 commits intophpDocumentor:masterfrom
lacatoire:feat/interface-properties

Conversation

@lacatoire
Copy link
Copy Markdown
Contributor

@lacatoire lacatoire commented Apr 10, 2026

Summary

PHP 8.4 allows declaring properties in interfaces using property hooks:

interface HasId
{
    public int $id { get; }
}

This was not supported, causing a crash: Expected an instance of any of Class_, Trait_. Got: Interface_.

  • Accept InterfaceInterface in PropertyDescriptor::setParent()
  • Add property collection to InterfaceInterface / InterfaceDescriptor with inheritance support
  • Assemble interface properties in InterfaceAssembler
  • Display properties in the default interface template

Fixes #4061

PHP 8.4 allows declaring properties in interfaces using property hooks.
Wire the property support through the descriptor layer and templates:

- Accept InterfaceInterface in PropertyDescriptor::setParent()
- Add property collection to InterfaceInterface and InterfaceDescriptor
- Assemble properties in InterfaceAssembler
- Display properties in the default interface template

Depends on phpDocumentor/Reflection#739.
Fixes phpDocumentor#4061
Comment thread src/phpDocumentor/Descriptor/InterfaceDescriptor.php Outdated
Replace manual property methods with the HasProperties trait, keeping
only the overridden getInheritedProperties() to handle interface
multi-parent inheritance.

Point composer to the reflection fork branch that adds
Interface_::getProperties() to fix PHPStan.
@jaapio
Copy link
Copy Markdown
Member

jaapio commented Apr 12, 2026

I merged your changes in reflection a new versio (6.6.0) contains the fixes.

InterfaceDescriptor uses the HasProperties trait but does not implement
ChildInterface, so the parent recursion branch in getMagicProperties() is
unreachable for it. PHPStan still observes the always-false instanceof
while analysing the trait in that context; a scoped ignoreError documents
why the report is expected.
…-parent inheritance

- Wrap Constants/Properties/Methods ToC links in {% if X is not empty %}
  to match class.html.twig and stop emitting dangling anchors for empty
  sections.
- Replace 'constants.deprecated' with 'constant.deprecated' inside the
  Constants loop (the loop variable is the singular form).
- Add a unit test covering getInheritedProperties() with multiple parent
  interfaces, which is unique to interfaces (extends A, B).
…operties

# Conflicts:
#	composer.json
#	composer.lock
@jaapio jaapio merged commit c4feb60 into phpDocumentor:master Apr 14, 2026
116 checks passed
@jaapio
Copy link
Copy Markdown
Member

jaapio commented Apr 14, 2026

Thanks for your help again!

@lacatoire lacatoire deleted the feat/interface-properties branch April 14, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support of Interface Properties

2 participants