
When I execute the new code folder, I get an error on one package that the class is not found.Įrror: Class 'BenMorel\GsmCharsetConverter\Converter' not found lock file into a new folder (the folder is at the same directory level as the original code folder). I then copied the code folder, including the. I successfully added a package and it is executing in my php code.
I have composer working in my MAMP environment. Please check them out and let us know your thoughts. This should fix it, if you indeed know for certain all other items are correct.ĭid I misspeak on any of this? Have questions/suggestions? Feel free to give feed back or compliments 😁Ĭurrent projects are and. To force the autoload file to regenerate just run the command below. Composer uses a cache file for speed and performance. If you've updated your composer file since you last ran composer install, it could be outdated. If you've confirmed all is right and you are banging your head against the wall, then this is probably what the issue is.
src/Service/dummy.php // folder names match the namespace exactly. src/service/dummy.php //service is lower when the first character should be capitalized. I've had a time where local dev didn't match, so it worked on my machine but then production complained. Note: some systems are case insensitive, so this may not apply but should still be practiced. Many times I've ran in to a missed casing issue. Also that there are no typos and the paths match casing, both upper and lower. namespace DeChamp\MyApp\Service // within file dummy.phpĬheck both the namespace at the top of your file, and the folder directory match up. This is what the autoloader will be matching against, so confirm your base folder that it's pointing to is correct.įor example if we have our psr-4 set to "DeChamp\\MyApp\\": "src/", that would mean that if I have a folder called "Service" inside of the "src" folder, then the namespace would be "DeChamp\MyApp\Service".Ĭheck that the namespace path matches the path to the file. Step 0 (thanks Kushal Niroula! see his comment below)Īs Kushal Niroula mentioned below, you should always check that you're importing the class at the top script, so do this first!Ĭheck the composer.json file, the autoload path. Typically it's just a typo or a uppercase where it should be lower or vice versa, in the namespace. So there are a few things you can do to fix the "Class '' not found" in PHP.
I use composer autoload to load my classes. I am getting a "Class '' not found" when running my code.