Skip to main content

PHP autoloading namespace on xampp

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 app\admin\modules\smartForm;
class smartForm {
/* Class logic*/
}

This is my file system:

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:\xampp\htdocs\php\smartfrom\app\system\autoLoader.php on line 3



source https://stackoverflow.com/questions/69713010/php-autoloading-namespace-on-xampp

Comments