Repository navigation
Open
Description
Description
The following code:
<?php
$depth = 0;
spl_autoload_register(function ($class) use (&$depth) {
$depth++;
$indent = str_repeat('| ', $depth);
echo $indent."$depth: $class\n";
if ($class == 'IFace') {
interface IFace {}
} elseif ($class == 'IFaceImplementor') {
class IFaceImplementor implements IFace {}
} elseif ($class == 'InterfaceOfMainParent') {
interface InterfaceOfMainParent
{
public function methodForSecondaryLspCheck(): IFace;
}
} elseif ($class == 'MainParent') {
abstract class MainParent implements InterfaceOfMainParent
{
public function methodForSecondaryLspCheck(): IFaceImplementor {}
}
} elseif ($class == 'Intermediate') {
abstract class Intermediate extends MainParent {}
} elseif ($class == 'Child1') {
class Child1 extends Intermediate {}
} elseif ($class == 'Child2') {
class Child2 extends Intermediate {}
} elseif ($class == 'EntrypointParent') {
abstract class EntrypointParent
{
abstract public function methodForLspCheck1(): MainParent;
abstract public function methodForLspCheck2(): MainParent;
}
} elseif ($class == 'Entrypoint') {
class Entrypoint extends EntrypointParent
{
public function methodForLspCheck1(): Child1 {}
public function methodForLspCheck2(): Child2 {}
}
}
$depth--;
});
class_exists(Entrypoint::class);Resulted in this output:
| 1: Entrypoint
| | 2: EntrypointParent
| | 2: Child1
| | | 3: Intermediate
| | | | 4: MainParent
| | | | | 5: InterfaceOfMainParent
| | | | | 5: Child2
Fatal error: During inheritance of MainParent, while autoloading Child2: Uncaught Error: Class "Intermediate" not found in php-wasm run script:29
Stack trace:
#0 php-wasm run script(20): {closure}('Child2')
#1 php-wasm run script(25): {closure}('MainParent')
#2 php-wasm run script(27): {closure}('Intermediate')
#3 php-wasm run script(37): {closure}('Child1')
#4 [internal function]: {closure}('Entrypoint')
#5 php-wasm run script(47): class_exists('Entrypoint')
#6 {main} in php-wasm run script on line 20
But I expected this output instead:
| 1: Entrypoint
| | 2: EntrypointParent
| | 2: Child1
| | | 3: Intermediate
| | | | 4: MainParent
| | | | | 5: InterfaceOfMainParent
| | | | | 5: IFaceImplementor
| | | | | | 6: IFace
| | 2: Child2
- Full reproduction repository: https://github.com/janedbal/php-bug-complex-inheritance-chain-autoloading
- 3v4l version: https://3v4l.org/G5fFe
- Broken since: PHP 8.1.0
PHP Version
PHP 8.5.0RC1 (cli) (built: Oct 8 2025 22:41:41) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.5.0RC1, Copyright (c) Zend Technologies
with Zend OPcache v8.5.0RC1, Copyright (c), by Zend Technologies
Operating System
No response
Reacted by Jan Tvrdík, Kryštof Prášil and Podles
Reacted by Jan Tvrdík and Kryštof Prášil
Activity
ndossche commentedon Oct 9, 2025
Didn't investigate yet, just ran a bisect which pointed to a38f4f9
EDIT: Oh this appears to happen when load_delayed_classes() is called in a nested way, and they start to operate on the same hash table and therefore the ordering of class loading becomes off...
Anyway I'm not too familiar with the whole autoloading+inheritance architecture
sedev91 commentedon Oct 15, 2025
Hello,
I hope this message finds you well.
I expected this output
but in truth I don't know anything about it.
Fix phpGH-20112: Fatal error during autoloading of complex inheritanc…