I am trying to autoload php class under namespace on xampp. But for some reason it cannot find class under its absolute path.
here is my autoloader:
spl_autoload_register(function($className){ require_once($_SERVER["DOCUMENT_ROOT"] .'/' . str_replace('\', '/', $className). '.php'); })
here is my class
namespace appadminmodulessmartForm; class smartForm { /* Class logic*/ }
This is my file system:
This i error i am getting:
Warning: require_once(C:/xampp/htdocs/app/admin/modules/smartForm/smartForm.php): Failed to open stream: No such file or directory in C:xampphtdocsphpsmartfromappsystemautoLoader.php on line 3
Advertisement
Answer
Looks like after 3 days i finally figure it out.
Instead of going trought absolute path you can choose relative path from autoloader file.
here is final include:
include_once(__DIR__.'..\'.$className.'.php');