I’m developing a library for guitar chords. In some files on the library I have something like this:
require_once "lib/GuitarChord.php";
require_once "lib/Chord.php";
require_once "lib/Key.php";
require_once "lib/Tuning.php";
How can I make this library so it doesn’t need to know where the other library files are?
This way a person could have the library files in any directory?
Create autoloaders for all locations where these classes might be.
For Example:
Then if you want to load the
ChordClass and you know it is in yourlibfolder, the autoloader will do the work for you when you do:You can attach many different autoloader callbacks with
spl_autoload_register