Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHP: __autoload
function __autoload($class_name) {
# If file name contains underscore convert them to folder marks
if (strpos($class_name, '_') !== false) {
$className = str_replace("_", "/", $class_name);
} else {
$className = $class_name;
}
# This where we usually contain all our classes
$path = dirname(__FILE__)."/classes/" . $className . '.php';
# echo $path;
# Check the obvious place first
if (file_exists($path)) {
require_once $path;
return true;
# file included no need to go forward
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment