note 74026 added to language.oop5.autoload
| From: | AndreaGiammarchi at osu1 dot php dot net | Date: | Wed, 21 Mar 2007 11:54:33 +0000 |
| Subject: | note 74026 added to language.oop5.autoload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124659@lists.php.net to get a copy of this message | ||
Another workaround for Exception problem (Klaus Schneider style)
<?php
define('CLASS_DIR', 'php/classes/');
function __autoload($name) {
if($exists = !class_exists($name) && file_exists($class =
CLASS_DIR.$name.'.class.php'))
require $class;
elseif(!$exists) {
eval('class '.$name.' extends Exception {}');
throw new $name('[__autoload] this file doesn\'t exists: '.$class);
}
}
try {
new Undefined;
}
catch(Undefined $e) {
echo $e->getMessage();
}
// You should use generic Exception too
catch(Exception $e) {
echo $e->getMessage();
}
?>
----
Server IP: 213.92.11.19
Probable Submitter: 82.84.14.219
----
Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php
Edit -- https://master.php.net/note/edit/74026
Del: integrated -- https://master.php.net/note/delete/74026/integrated
Del: useless -- https://master.php.net/note/delete/74026/useless
Del: bad code -- https://master.php.net/note/delete/74026/bad+code
Del: spam -- https://master.php.net/note/delete/74026/spam
Del: non-english -- https://master.php.net/note/delete/74026/non-english
Del: in docs -- https://master.php.net/note/delete/74026/in+docs
Del: other reasons-- https://master.php.net/note/delete/74026
Reject -- https://master.php.net/note/reject/74026
Search -- https://master.php.net/manage/user-notes.php