Why not, finds the class namespace?

there is a file for work with databases (beginning of file) (the file is called User.php):

 namespace api\models;

 require_once '../db/Model.php';

 use api\db\Model;

 class User extends Model
<br / > I User.php connected to another file (in file main.php) (beginning of file)<br><pre><code class="php"><?php namespace api\classes; include_once "../models/User.php"; use api\models\User; /** * main class */ class main {</code--></code></pre><code class="php"><br> And after I create a User object <code class="php">$user = new User;</code><br> I wrote Fatal error: Uncaught Error: Class 'api\models\User' not found<br> Please tell me, why does not find the class.</code>
June 3rd 19 at 19:05
2 answers
June 3rd 19 at 19:07
About auto read
include_once "../models/User.php";
this farm, which should not work.
June 3rd 19 at 19:09
The file may be actually not connected, replace require_once (What if the file is not connected, the program stopped execution) try an absolute path to the file.
And / Or issue registers which do not see.

And generally I advise to look in the direction of startup classes.
You can for example have composer take advantage of the steep loader.

Find more questions by tags PHP