Created
April 2, 2012 06:59
-
-
Save serkanyersen/2281327 to your computer and use it in GitHub Desktop.
PHP: __autoload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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