In order for us to use our classes, we'll need to add some code to Bones
so that we can automatically load class names as they are used. This will achieve that, so we don't have to continuously include more files as we add new classes.
Add the following code to lib/bones.php:
<?php define('ROOT', __DIR__ . '/..'); require_once ROOT . '/lib/sag/src/Sag.php'; function __autoload($classname) { include_once(ROOT . "/classes/" . strtolower($classname) . ".php"); }
We added a __autoload
function to our Bones
library that will give PHP a last attempt to load a class name if it can't find the class. The __autoload
function is passed the $classname
, and we use the $classname
to find the file of the named class. We are making the requested $classname
lowercase using the strtolower
function so that we can find the named file. We then added the root of the working directory with the ROOT
constant and the classes
folder....