PHP namespace confusion, class not found

I have two classes in one folder in my own files. But when I try to extend one to another, it gives a namespace and the class does not detect an error.

Info: This is the first time I am extending a class using a namespace. Also the nested namespace is new to me. DB\CRUDSo maybe I'm doing completely wrong with the namespace.

Error message:

Fatal error: Class 'DB\AT_Database' not found in /var/www/...

DB class

File: AT_Database.php

namespace DB;

class AT_Database
{
    ...
}

CRUD class

File: AT_CRUD.php

namespace DB\CRUD;


use DB\AT_Database;

class AT_CRUD extends AT_Database
{

    public function __construct()
    {

    }

}
+4
source share
1 answer

It may be a stupid mistake, or maybe I missed it (I should not have programmed it), and this is loading the class sequence.

, , , -, ​​.

, glob , .

foreach ( glob( $this->classes_dir . "/*.php" ) as $class ) {
    include_once $class;
}

AT_CRUD.php AT_Database.php. , php . , AT_Database AT_CRUD, .

, php AT_CRUD , AT_Database, , - , @prehfeldt .

+2

All Articles