Skip to content

Instantly share code, notes, and snippets.

@gowon
Last active September 13, 2019 08:16
Show Gist options
  • Save gowon/84584b6443b2bb60da5b to your computer and use it in GitHub Desktop.
Save gowon/84584b6443b2bb60da5b to your computer and use it in GitHub Desktop.
Directory-based autoload function
<?php
/* Directories that contain classes */
$classesDir = array (
ROOT_DIR.'classes/',
ROOT_DIR.'firephp/',
ROOT_DIR.'includes/'
);
function __autoload($class_name) {
global $classesDir;
foreach ($classesDir as $directory) {
if (file_exists($directory . $class_name . '.php')) {
require_once ($directory . $class_name . '.php');
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment