1) I've written a few classes and interfaces that I want to place in the "automatically loaded classes" list, if such a list exists. In all, I have a folder containing 30 PHP file, each containing a class or an interface. How do I go about making them part of the default PHP library for my computer / server? As I'm sick of having to write an autoload on top of my PHP files.
2) Secondly, are "include" and "require" essentially the only way to import files? Is there a cleaner way to load classes from files, like "import" in Java? A way that doesn't simply add the file into the file from which include was called?
You are looking for something like this ...
// autoloader
function autoloader($class)
{
$filename = BASE_PATH . '/inc/' . str_replace('\\', '/', $class) . '.php';
include_once($filename);
}
spl_autoload_register('autoloader');