I’m trying to create an PHP object that can load objects in other files on demand when needed. My problem is that when I reference the files based on file location for the class definition, it can not find the files. So file structure:
/Test.php
/os/os.php (extends kernel)
/os/kernel.php
/os/libraries/lib1.php
/os/libraries/lib2.php
/os/libraries/lib3.php
In kernel.php, the libraries are referenced as ‘libraries/lib1.php’. If I create an “os” object in Test.php. The lib files are not found.
Use a good naming convention for your classes, include_path and use spl_autoload.
For exemple:
Name your classes like this:
class Os
class Kernel
class Libraries_Lib1
…
Register your include path
And use an autoload: