php / php/doc-en

Undocumented behaviour change in 8.5: `self`/`parent` now accepted in intersection types

Open Beginner friendly
#5,639 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

https://3v4l.org/MC5jDN

Suggested fix
  • Add an UPGRADING entry 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.