Dev Notes

Software Development Resources by David Egan.

Laravel Reflection Error when Class Contains Errors


Debugging, Errors, Laravel
David Egan

This is a quick note - intended to be a memory jogger.

Laravel will throw a ReflectionException error if a class contains an error.

For example:

ReflectionException in Route.php line 339: Class App\Http\Requests\CreateLeadRequest does not exist

This is pretty logical - if the class can’t be instantiated, it doesn’t exist.

It can be confusing if you’re looking at your project file tree and can see the class file (“I can see it - the class exists!”). In my case, I checked the calling class several times before bothering to check the content of the class that was being called - which was missing a comma.

To prevent this kind of thing:

  • Use a PHP linter - here’s one for Atom
  • Check all the classes involved, especially the one you’re calling - don’t assume you’ve got an autoloading issue

comments powered by Disqus