- spl_autoload_register: documentation ( source)
- class_exists: documentation ( source)
- str_repeat: documentation ( source)
<?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);