Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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