Search code examples
phpnamespacesphpstorm

Can't access to class from .php file (PhpStorm)


Sorry for stupid question, but I really don't understand what's wrong.

I have a separate class User and want to make its object in .php file. I went to Settings/Directories and marked folder users like Source also added a prefix(PSR-4). In Test.php I imported needed class.

But the result is the same:

Fatal error: Class 'Users\User' not found in E:\Server\Apache24\htdocs\lab1\users\Test.php on line 10

User.php:

<?php
namespace Users;

class User
{
    var $name;
    var $login;
    var $password;
}

Test.php:

<?php

use Users\User;

$user1 = new User;

Settings/Directories


Solution

  • You should change test.php

    <?php
    require_once('user.php');
    use Users\User;
    
    $user1 = new User;