Stepping back into debugging

In PHP, we have functions like var_dump(), dump() and dd() that are used to debug code and print output to the screen.

In Drupal, we have functions like dpm() and kint(), too.

These functions are great for simple debugging but sometimes I need more, which is when I reach for a step debugger - namely, Xdebug.

This is common when working in complex legacy code, where you need to be able to see a breakpoint and step through the code to see what path it takes and what the state is at each step.

Enter Xdebug

Xdebug is a tool I use fairly often and something I have configured on an individual project basis.

This week, I spent some time adding it to a new project and ensured my notes and documentation still worked.

I use Docker and Docker Compose on Linux, so there are slight changes compared to running PHP natively, so I wanted to make sure it still works.

I've added my latest setup to my Drupal Docker Example repository and plan to add it to my standard Build Configs setup for Drupal projects.

If you use Docker Compose on Linux, it may be useful for you.

If you haven't tried Xdebug before, I suggest giving it a try and see if improves your debugging.

- Oliver

P.S. If you're creating a new Drupal module, try my free Drupal module template.

Was this interesting?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an Acquia-certified Drupal Triple Expert with 17 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.