Abstract properties (hooks) in traits
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
At the moment such code does not work (8.4 and 8.5/master), which does not seem very logical:
<?php
trait Example
{
abstract public string $property {
get;
}
}
class ExampleImpl
{
use Example;
public function __construct(
public readonly string $property,
) {}
}
Produces:
Fatal error: ExampleImpl and Example define the same hooked property ($property) in the composition of ExampleImpl. Conflict resolution between hooked properties is currently not supported. Class was composed
According to RFC (https://wiki.php.net/rfc/property-hooks#interaction_with_traits), traits do not actually support properties, but at least such primitive conflict resolution would be nice to have.
P.S. Is it worth writing to internals for RFC if there is no way to send a PR?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided trait and hooked-property reproducer, then read the property-hooks RFC section on trait interaction. Trace how trait composition handles the abstract hooked property and the implementing constructor-promoted property. Done means the example composes without the reported conflict while preserving the intended property-hook behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100