I've been trying to get psr-4 autoloading work for over a week now with no success.
My file structure is as follows:
-Project
-src
-classes
session.php
-vendor
index.php
I've created the psr-4 autoload function as follows:
"autoload": {
"psr-4": {
"classes\\": "src/classes"
}
}
after using composer dump-autoload -0 ,inside my session.php class I gave the namespace:
namespace classes;
class session{
public static function exist($name){
return(isset($_SESSION[$name])) ? true : false;
}
I then required the autoloader and used the use function to name the session class as follows:
use src\classes\session as session;
require_once('vendor/autoload.php');
session::put('test', 'test');
after opening up the index.php page, I get a
Fatal error: Class 'src\classes\session' not found in /var/www/test/Project/index.php on line 10
is my directory structure / php correct? I've tried many different guides online and can't seem to get it to work.