- spl_autoload_register: documentation ( source)
<?php
spl_autoload_register(function ($c) {
if ('ChildClass' === $c) {
class ChildClass extends ParentClass {}
}
if ('ParentClass' === $c) {
throw new \Exception('ParentClass not found.');
}
});
try {
new ChildClass();
} catch (\Exception $e) {
echo $e->getMessage();
}