Skip to content

Instantly share code, notes, and snippets.

@blacksmoke26
Last active March 29, 2016 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blacksmoke26/8466134 to your computer and use it in GitHub Desktop.
Save blacksmoke26/8466134 to your computer and use it in GitHub Desktop.
Autoload Register PHP Files
<?php
/**
* Autoload Register the Directory's PHP Classes
*
* @author Junaid Atari <mj.atari@gmail.com>
*
* @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