Skip to content

Add support for PHP 8.4 interface properties#739

Merged
jaapio merged 2 commits intophpDocumentor:6.xfrom
lacatoire:feat/interface-properties
Apr 12, 2026
Merged

Add support for PHP 8.4 interface properties#739
jaapio merged 2 commits intophpDocumentor:6.xfrom
lacatoire:feat/interface-properties

Conversation

@lacatoire
Copy link
Copy Markdown
Contributor

Summary

PHP 8.4 allows declaring properties in interfaces using property hooks:

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

This was not supported by the reflection library, causing a crash when phpDocumentor encountered interface properties (Expected an instance of any of Class_, Trait_. Got: Interface_).

  • Add $properties array, getProperties(), and addProperty() to Interface_, following the same pattern as Trait_
  • Add Interface_::class to the assertion in Factory\Property::doCreate()
  • Add unit test for Interface_ property accessors
  • Add integration test parsing a PHP 8.4 interface with hooked properties

Fixes phpDocumentor/phpDocumentor#4061

lacatoire added a commit to lacatoire/phpDocumentor that referenced this pull request Apr 10, 2026
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
PHP 8.4 allows declaring properties in interfaces using property hooks.
Add getProperties() and addProperty() to Interface_, and allow the
Property factory to accept Interface_ as a valid container.

Fixes phpDocumentor/phpDocumentor#4061
- Remove same-namespace import of Property in Interface_Test
- Add RequiresPackage constraint for nikic/php-parser >= 5.2 on
  the integration test, as older versions cannot parse interface
  property syntax
Copy link
Copy Markdown
Member

@jaapio jaapio left a comment

Choose a reason for hiding this comment

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

Thanks this looks good, I will merge this later when I'm back at my computer.

@jaapio jaapio merged commit 60b6499 into phpDocumentor:6.x Apr 12, 2026
40 checks passed
@lacatoire lacatoire deleted the feat/interface-properties branch April 12, 2026 18:57
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.

2 participants