note 81649 deleted from language.oop5.autoload by betz
| From: | betz@php.net | Date: | Thu, 13 Mar 2008 15:33:09 +0000 |
| Subject: | note 81649 deleted from language.oop5.autoload by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137024@lists.php.net to get a copy of this message | ||
Note Submitter: cskakun at gmail dot com
----
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.');
}
?>