It's my first time using autoloading but I keep getting the error saying my class can't be found:
Fatal error: Class 'Classes\Sunrise\DB' not found in my\sample\path\.sunrise.app\init.php on line 52
Edit: Line 52 is where I use a static method from the DB class. For some reason, PHP says it can't find the DB class.
My structure:
order (Folder)
+ index.php
.sunrise.app
+ init.php
+ ordersetup.php
+ Classes (Folder)
+ Sunrise (Folder)
+ DB.php
The file init.php contains my autoloader and is included in the file ordersetup.php which in turn is included in order/index.php with include_once '../.sunrise.app/ordersetup.php'; In the file .sunrise.app/init.php I need to use the DB class but am met with the error shown above. What am I doing wrong?
My autoloader in .sunrise.app/init.php:
function my_autoload($class_name) {
include $class_name. '.php';
}
spl_autoload_register('my_autoload');
My DB class in classes/Sunrise/DB.php:
<?php namespace Classes\Sunrise;
use PDO;
class DB { ... }
Edit: The folder Sunrise is under the folder Classes
classesfolder is actuallyClasses. It's capitalized.use PDOstatement will call the autoloader for a class calledPDOin theClasses\Sunrisenamespace. If you want thePDOfrom the global namespace, you'll have to writeuse \PDO, where the leading `` references the global namespacerequireone of these files manually.