声明和使用PHP命名空间

声明和使用PHP命名空间,php,namespaces,Php,Namespaces,请帮助识别此代码中的错误 我有以下文件夹结构: Role.php <?php namespace src\db; class Role extends Table { public $name = ""; // TODO - Insert your code here public function __construct() { parent::__construct(); // TOD

请帮助识别此代码中的错误

我有以下文件夹结构:

Role.php

<?php
namespace src\db;

class Role extends Table
{
    public $name    = "";
    
    // TODO - Insert your code here
    public function __construct()
    {
        parent::__construct();
        // TODO - Insert your code here
    }
}

如果您没有使用自动加载器,那么您必须使用require()或include()包含定义类的文件。

我在索引页中添加了自动加载器,它正在工作。谢谢
<?php
namespace src\db;

class Role extends Table
{
    public $name    = "";
    
    // TODO - Insert your code here
    public function __construct()
    {
        parent::__construct();
        // TODO - Insert your code here
    }
}
   <?php
    
    use src\db\Role;
    
    $role = new Role();
    
    $role->name = "Admin";
    
    $role->Save();