Skip to content

Instantly share code, notes, and snippets.

@ChrisMcKee
Created October 6, 2011 20:52
Show Gist options
  • Save ChrisMcKee/1268645 to your computer and use it in GitHub Desktop.
Save ChrisMcKee/1268645 to your computer and use it in GitHub Desktop.
PHP AutoLoad Magic Method, this is for pre SPL implementations
<?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