Last active
March 29, 2016 11:04
-
-
Save blacksmoke26/8466134 to your computer and use it in GitHub Desktop.
Autoload Register PHP Files
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
<?php | |
/** | |
* Autoload Register the Directory's PHP Classes | |
* | |
* @author Junaid Atari <[email protected]> | |
* | |
* @param string Path to direcetory | |
* @param string Files extension | |
* @return bool TRUE on registered | FALSE | |
*/ | |
function autoloadDir ( $dir, $ext='.php' ) | |
{ | |
if ( !is_dir ( $dir ) ) | |
return false; | |
// Set path as include | |
set_include_path ( $dir ); | |
// Files extension | |
spl_autoload_extensions ( $ext ); | |
// Register | |
return spl_autoload_register (); | |
} | |
/* | |
EXAMPLE: | |
# + /foo/bar (Directory) | |
# - User.php | |
# - Database.php | |
autoloadDir ( '/foo/bar' ); | |
$user = new User (); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment