When creating a library, I always provide an Autoloader class that handles autoload for the library. The autoloader is registered as follows:
require_once 'path/to/PHP-Parser/lib/PHPParser/Autoloader.php'; PHPParser_Autoloader::register();
I'm not sure how to handle this if my library depends on another library. Imagine that PHPParser depends on a PHPLexer . Now, using the library, you need to write:
require_once 'path/to/PHP-Lexer/lib/PHPLexer/Autoloader.php'; PHPLexer_Autoloader::register(); require_once 'path/to/PHP-Parser/lib/PHPParser/Autoloader.php'; PHPParser_Autoloader::register();
If there is more than one dependency or dependencies depend on the dependencies themselves, this can quickly get confused.
So how should handling dependency loading ?
One of my ideas was that the library should also handle autoload for these dependencies, but that is simply not the case. Another idea would be to not provide an autoloader at all and assume that people are using UniversalClassLoader . This, although it does not seem correct.
NikiC source share