Answer the question
In order to leave comments, you need to log in
Composer autoload. What have I done wrong?
How does composer autoload work?
Folders
-src
--doctor
---domain
----entity (Doctor.php)
----services (RegisterDoctorServices.php)
index.php
use Doctor\Entity\Doctor;
try {
require_once __DIR__ . './vendor/autoload.php';
new Doctor();
} catch (Error $e) {
echo $e;
}
{
"autoload": {
"psr-4": {
"Doctor\\": "./src/doctor/domain"
}
}
}
use Doctor\Entity\Doctor;
try {
require_once __DIR__ . './vendor/autoload.php';
new Doctor();
} catch (Error $e) {
echo $e;
}
namespace Doctor\Entity;
use Doctor\Services\RegisterDoctorServices;
class Doctor {
public function __construct() {
echo 'Doctor works!';
new RegisterDoctorServices();
}
}
<?php
namespace Doctor\Services;
class RegisterDoctorServices { }
Doctor works!
Fatal error: Uncaught Error: Class 'Doctor\Services\RegisterDoctorServices' not found in D:\OSPanel\domains\ddd\src\doctor\domain\entity\Doctor.php:54 Stack trace: #0 D:\OSPanel\domains\ddd\index.php(14): Doctor\Entity\Doctor->__construct() #1 {main} thrown in D:\OSPanel\domains\ddd\src\doctor\domain\entity\Doctor.php on line 54
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question