Psr-4 I cannot autoload

can I ask some help I can’t autoload the Class, I have this folder structure

Employee.php

  namespace app\Employee;

    class Employee
    {
       public function __construct(){
           echo "hello employee";
    
       }
    
    }

Index.php

use app\Employee;


  $emp = new Employee;

composer.json

{
  "autoload": {
    "psr-4": {
       "Employee\\":"app/Employee"
    }
  }
}

In your PHP code, your namespace is “app\Employee”, not just “Employee”.

I change that but still I cannot load. is there another file in vendor that I will load ?

Have you included the Autoloader from the Composer vendor directory?

include_once 'vendor/autoload.php';
use app\Employee;
$emp = new Employee;
1 Like

wow this fixed! Thank you…:smile:

glad to be of help, happy coding

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.