How to handle Uncaught Error: PHP/Composer class not found?
P粉304704653
P粉304704653 2023-09-04 13:46:14
0
1
493
<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粉304704653
    P粉304704653

    reply all(1)
    P粉618358260

    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.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template