Search code examples
phpcomposer-phpautoload

How handle Uncaught Error : Class not found PHP / Composer?


I'm beginning a project with oop as beginner and I'm trying to use some classes that I think are recognized by vscode and composer because when I click on their namespaces it lead me to right class but when I run the code in the browser I have fatal error telling me that my class is not found.

I try many things :

  • Delete the vendor folder and install it again

  • Changing the case of my namespaces they was all in lowercase then I read that I had to start them with the first letter in uppercase (Nothing has change)

  • I checked the path of these folders and everything is fine regardless to the realpath built-in function of php

  • I update my modification on the composer.json with the composer-dump-autoload command nothing change

I don't really know where I messed up :

Project Folder Structure

Its the index.php file (in the public folder) : enter image description here

The database.php file :

enter image description here

The article.php file : enter image description here

And finally my composer.json :

enter image description here

I don't know if its useful to say it but when I try to make a require of my model file in the index.php file its working but as I removed the require its not longer working


Solution

  • I found the solution it was related to the path that I set on composer.json my classes with the namespace "Articles" wasn't able to load correctly even if vscode can read it only because I haven't wrote the relative path like I should the "src" folder was on root but I've gone up too far on my directory that why it wasn't working so I just removed the dots and everything works fine.