Home  >  Q&A  >  body text

How to handle Uncaught Error: PHP/Composer class not found?

<p>I'm starting a project with oop as a beginner and I'm trying to use some classes that I think will be recognized by vscode and composer because when I click on their namespace it directs me to the correct class, but when I run the code in the browser I get a fatal error telling me that my class cannot be found. </p> <p>I tried a lot of things: </p> <ul> <li><p>Delete vendor folder and reinstall</p> </li>
  • </li> <li><p>I checked the paths to these folders and everything is fine regardless of php's realpath built-in function</p> </li> <li><p>I used the composer-dump-autoload command to update the modifications to composer.json without any changes</p> </li> </ul> <p>I really don’t know where I messed up:</p> <p>Its index.php file (in the public folder): </p> <p>database.php file: </p> <p>article.php file: </p> <p>Finally my composer.json: </p> <p>I don't know if it's helpful to say this, but when I try to require my model file in the index.php file, it works, but when I remove the requirement, it doesn't work anymore</p>
  • P粉304704653P粉304704653432 days ago471

    reply all(1)I'll reply

  • P粉618358260

    P粉6183582602023-09-05 09:54:17

    I found the solution, it had to do with the path I set on composer.json, even though vscode could only read it, my class with namespace "Articles" couldn't load properly because I didn't Writing relative like I was supposed to put the "src" folder on the root, but I went too far up the directory so it didn't work, so I just removed the dots and everything worked fine.

    reply
    0
  • Cancelreply