Undocumented behaviour change in 8.5: `self`/`parent` now accepted in intersection types
Nobody has claimed this yet.
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
Description
Affected page
https://www.php.net/manual/en/language.types.declarations.php
Issue description
In 8.1–8.4, using self or parent in an intersection type is a compile-time fatal error. In 8.5 it compiles (in a normal class), as a side effect of #17755. I couldn't find this documented in UPGRADING, and the RFC still says these types are not allowed.
Could this be added to the docs?
Note on scope
The new behaviour does not apply uniformly (as I understand) it still fatals in traits, in closures (bound or unbound), for anonymous classes, and for static. Any doc note should mention this so readers don't assume self&X works everywhere.
Refs
Steps to reproduce
<?php
interface FactoryConfig {}
interface Factory
{
public function make(): self&FactoryConfig;
}
- 8.1.0 – 8.4.x:
Fatal error: Type self cannot be part of an intersection type - 8.5.0 – 8.5.7: compiles with no error
Suggested fix
- Add an
UPGRADINGentry for the change. - Update the manual (Type declarations), which still states
self/parent/static"result in an error" — this likely belongs in php/doc-en.
Contributor guide
No contributing guide indexed for this repository
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 Type declarations manual page named in the issue and compare its statement about self, parent, and static in intersection types with the PHP 8.5 behavior and the listed exceptions. Check the referenced pull request and the UPGRADING guidance, then update the documentation so the supported scope and limitations are explicit and the version change is recorded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100