note 77471 added to language.oop5.autoload
| From: | rlee0001 at sbcglobal dot net | Date: | Thu, 30 Aug 2007 20:16:22 +0000 |
| Subject: | note 77471 added to language.oop5.autoload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129918@lists.php.net to get a copy of this message | ||
If you would like __autoload to throw an exception when the class cannot be loaded instead of
causing a fatal error, consider this:
<?php
function __autoload ($className)
{
$fileName = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
$status = (@include_once $fileName);
if ($status === false) {
eval(sprintf('class %s {func' . 'tion __construct(){throw new
Project_Exception_AutoLoad("%s");}}', $className, $className));
}
}
$pageController = 'Project_My_Class'; // "Project/My/Class.php"
try {
$obj = new $pageController();
} catch (Project_Exception_AutoLoad $e) {
header('HTTP/1.0 404 Not Found');
printf('<h1>Not Found</h1><p>The requested page %s was not found on this
server.</p><hr /><em>$id$</em>', $_SERVER['REQUEST_URI']);
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 71.42.115.242
----
Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php
Edit -- https://master.php.net/note/edit/77471
Del: integrated -- https://master.php.net/note/delete/77471/integrated
Del: useless -- https://master.php.net/note/delete/77471/useless
Del: bad code -- https://master.php.net/note/delete/77471/bad+code
Del: spam -- https://master.php.net/note/delete/77471/spam
Del: non-english -- https://master.php.net/note/delete/77471/non-english
Del: in docs -- https://master.php.net/note/delete/77471/in+docs
Del: other reasons-- https://master.php.net/note/delete/77471
Reject -- https://master.php.net/note/reject/77471
Search -- https://master.php.net/manage/user-notes.php