DEV Community

Cover image for EXCEPTION (CLASS .... NOT FOUND) while DEBUGGING
Samuel Boadu
Samuel Boadu

Posted on

EXCEPTION (CLASS .... NOT FOUND) while DEBUGGING

The art of debugging is very important as it could save you lot of time and headaches. Tools used

  1. Laravel
  2. Visual Studio Code(VSCode)
  3. Xdebug
  4. PHP Debug extension for Visual Studio Code (Debug support for PHP with Xdebug)
  5. Xdebug helper(Browser Extension)

Am going to skip the installation of this tools as once you encounter the "Class not found exception" then you have passed the installation stage.

After installing PHP debug extension and accessing its launch.json file from .vscode directory. You will see 3 different settings in configurations which you must take note of base on the name.

launch.json

Without the use of imported Classes in your debugging script you are likely not to experience any issues with any of these configurations. eg. using name: Launch currently open script

script without the usage of imported classes

For Laravel application the entry point is the index.php file which is inside the public folder. These file loads all the required files to handle request from the browser. So when we use the browser extension debug helper together with our break points we wont' have the exception: "Class .... not Found"

Class Not Found

The Solution
Change the debug configurations option name to Listen for Xdebug

Listen for Xdebug

And enable debugger helper extension in the browser.

enable debugger helper

After enabling the debug helper extension and refreshing the page again we see that the page keeps loading and never stops because our first break point has been hit awaiting our next action

first break point hit

We can see that our $user variable is not initialized yet from the VARIABLES SECTION.

When we click on continue to the next break point, we now see the $user variable being initialize which we can now inspect.

Debug variable set for inspection

Congratulations!!!!. Class not found exception during debugging in laravel is sorted. Let me know what you think as sharing helps us learn better.

Top comments (0)