Created
October 6, 2011 20:52
-
-
Save ChrisMcKee/1268645 to your computer and use it in GitHub Desktop.
PHP AutoLoad Magic Method, this is for pre SPL implementations
This file contains 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
<?php | |
function __autoload ($class_name) | |
{ | |
if (!class_exists($class_name, false)) { | |
$class_file_path = str_replace('_', '/', $class_name) . '.php'; | |
require($class_file_path); | |
} | |
} | |
/*or*/ | |
function __autoload($class_name) | |
{ | |
$filename = str_replace('_', DIRECTORY_SEPARATOR, strtolower($class_name)) . '.php'; | |
$file = $filename; //Concat filename with defined app root | |
if (!file_exists($file)) | |
{ | |
return FALSE; | |
} | |
include($file); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment