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.
Affected page
https://www.php.net/manual/en/language.types.declarations.php
Issue description
In 8.1–8.4, using
selforparentin 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 inUPGRADING, 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 assumeself&Xworks everywhere.Refs
Steps to reproduce
Fatal error: Type self cannot be part of an intersection typehttps://3v4l.org/MC5jDN
Suggested fix
UPGRADINGentry for the change.self/parent/static"result in an error" — this likely belongs in php/doc-en.