note 81649 added to language.oop5.autoload
| From: | cskakun at gmail dot com | Date: | Sat, 08 Mar 2008 06:28:30 +0000 |
| Subject: | note 81649 added to language.oop5.autoload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136833@lists.php.net to get a copy of this message | ||
A quick and easy way to auto loading from multiple directories ...
<?php
try
{
function __autoload($class)
{
// if class exists in the classes folder, classes/name_class.php
if(file_exists("classes/{$class}_class.php"))
{
$class_file = "classes/{$class}_class.php";
}// if class exists in the exceptions folder
else if(file_exists("exceptions/{$class}_exception.php"))
{
$class_file = "exceptions/{$class}_exception.php";
}// if class exists in the interfaces folder
else if(file_exists("interfaces/{$class}_interfaces.php"))
{
$class_file = "interfaces/{$class}_interfaces.php";
}
else
{
// oopps! could not find the class
throw new Excpetion($class);
}
include $class_file;
}
}
catch(Exception $exception)
{
die('Class "' . $exception->getMessage() . '" does not exist and could
not be loaded.');
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 24.64.250.179
----
Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php
Edit -- https://master.php.net/note/edit/81649
Del: integrated -- https://master.php.net/note/delete/81649/integrated
Del: useless -- https://master.php.net/note/delete/81649/useless
Del: bad code -- https://master.php.net/note/delete/81649/bad+code
Del: spam -- https://master.php.net/note/delete/81649/spam
Del: non-english -- https://master.php.net/note/delete/81649/non-english
Del: in docs -- https://master.php.net/note/delete/81649/in+docs
Del: other reasons-- https://master.php.net/note/delete/81649
Reject -- https://master.php.net/note/reject/81649
Search -- https://master.php.net/manage/user-notes.php