سلام دقیقه ۳۵ اونجای که نیم اسپیس اضافه شد دیگه اتو لودر من کار نمیکنه
Person.php
namespace App\\Classes;
class Person {
private $name;
public function __construct()
{
$this->name = static::class . "-" . rand(100 , 999);
}
public function sayHello()
{
echo "Hello, my name is " . $this->name . PHP_OS . PHP_EOL;
}
}
-----------------------------------------------------------------------------------------------------------------
main.php
include "autoload.php";
// include "Person.php";
// include "Student.php";
// include "Teacher.php";
$p1 = new App\\Classes\\Person();
$p1->sayHello();
$s1 = new App\\Classes\\Student();
$s1->sayHello();
$t1 = new App\\Classes\\Teacher();
$t1->sayHello();
-----------------------------------------------------------------------------------------------------------------
autoloader.php
function my_autoloader($class)
{
$classFile = __DIR__ . "/$class.php";
if (file_exists($classFile) && is_readable($classFile)){
include $classFile;
// echo 'from autoload my_autoloader =>' . $class . ' used ' . PHP_EOL;
}else{
echo ("Could not find class $classFile");
}
}
spl_autoload_register('my_autoloader');
این هم متن خطای که به من میده
Could not find class /var/www/html/OOP/autholoading/App\\Classes\\Person.php
Fatal error: Uncaught Error: Class "App\\Classes\\Person" not found in /var/www/html/OOP/autholoading/main.php:7 Stack trace: #0 {main} thrown in /var/www/html/OOP/autholoading/main.php on line 7