Class not found. Namespace and Composer psr-4

Asked

Viewed 103 times

0

Guys I did everything you say in the other questions on the subject, but it didn’t solve my problem. So I opened a new question.

My class is not being found.

this is my structure:

project
   _app
      |-- User.php
   vendor
      |-- composer
      |-- autoload.php
   composer.json
   index.php

This is my class:

<?php
namespace project\_app;

class User {}

This is my index:

<?php
require __DIR__ . "/vendor/autoload.php";

use \project\_app\User;

$user = new User;

?>

This is the Commodore:

"autoload": {
    "psr-4": {
         "project\\": "_app/"
    }
}

This is the error returned:

( ! ) Fatal error: Uncaught Error: Class 'project\_app\User' not found in C:\xampp\htdocs\project\index.php on line 18
( ! ) Error: Class 'project\_app\User' not found in C:\xampp\htdocs\project\index.php on line 18
  • You have _app left in the namespace, or you should create a _app directory inside _app and put User.php there.

1 answer

0

You are referencing "project" to "_app" folder, so you no longer need to repeat this "_app";

Ex:

<?php
namespace project;

class User {}

...

 <?php
 require __DIR__ . "/vendor/autoload.php";
 use project\User;
 $user = new User;

After doing this test again, if you have an error update the Poser autoloader:

composer dump-autoload -o

Browser other questions tagged

You are not signed in. Login or sign up in order to post.