Skip to content

Instantly share code, notes, and snippets.

@serkanyersen
Created April 2, 2012 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save serkanyersen/2281327 to your computer and use it in GitHub Desktop.
Save serkanyersen/2281327 to your computer and use it in GitHub Desktop.
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