Reputation: 329
I have autoload.php . This is running for auto loading my classes. I want to include autoload.php as auto my all php files in main folder.
Like:
include_to("index.php, example.php, ............... , other.php");
Meantime I know php's running style.
Upvotes: 0
Views: 2831
Reputation: 26699
You can use the auto_prepend_file setting to include the file in all your scripts.
Upvotes: 3
Reputation: 58444
You are doing it wrong.
Instead you should be using spl_autoload_register()
to create an autoloader, which load file. if it cannot find the class you use.
spl_autoload_register(function( $className ){
$filepath = '/path/to/files/' . strtolower( $className ) . '.php';
if ( !file_exists( $filepath ) )
{
$message = "Cannot load class: $className. ";
$message .= "File '$filepath' not found!";
throw new Exception( $message );
}
require $filepath;
});
Upvotes: 7