note 84853 deleted from language.oop5.autoload by crell
| From: | crell@php.net | Date: | Mon, 04 Apr 2022 16:15:31 +0000 |
| Subject: | note 84853 deleted from language.oop5.autoload by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218043@lists.php.net to get a copy of this message | ||
Note Submitter: matias dot cohen at gmail dot com
----
Another way of throwing exceptions inside an __autoload() function:
<?php
function myExceptionHandler($e) {
// Add code here
}
set_exception_handler('myExceptionHandler');
function __autoload($class) {
if (class_exists($class, false) || interface_exists($class, false)) {
return;
}
try {
@require_once('path/to/' . $class . '.php');
if (!class_exists($class, false) || !interface_exists($class, false)) {
throw new Exception('Class ' . $class . ' not found');
}
}
catch (Exception $e) {
myExceptionHandler($e);
}
}
?>