Debugging

A topic that is probably not covered enough. If you do not have debugging working in your IDE environment then you are sadly wasting a lot of your own time. A debugger allows you to step through problem code and figure out what is going wrong without adding all those die(), var_dump() and print_r() statements.

Tina4 helps a little with the initial debugging by showing decent error messages and identifying the code where your errors occurred but the most important thing is to install x-debug for PHP and get yourself up and running.

Installing a debugger can be a bit painful at first however once you have one working the rewards are self evident.

Get started by installing Xdebug, here are some pointers below for the various OS:

Windows - install XDebug
Linux & Mac - try a PECL install first otherwise you are going to be compiling from source code

PHP.ini

Please be aware that the latest versions of x-debug has changed somewhat and the configurations that used to work are no longer valid. Below is a configuration that works.

   [Xdebug] 
   zend_extension=xdebug
   xdebug.mode = debug
   xdebug.start_with_request=yes

Running Tina4 in debug mode

If you are using PHP Storm or IntelliJ then the following will get you started with little configuration.

   XDEBUG_CONFIG="client_host=127.0.0.1" composer start 8080

In your IDE look for the icon that looks like a telephone with a bug below it

_

Clicking it on will allow the IDE to start listening for a debugging request based on the command you ran before. Below is how it looks when the IDE is listening for a debugging connection.

_

Once you hit up your web page on http://localhost:8080, the debugger should activate and you need to accept the connection.

_

Add break points in your code by clicking on the left margin where you want the debugger to stop and you should get something like this

_

  • Don't forget to turn off your debugger telephone when you're done
  • Learn shortcut keys like F8 - step and F7 - step into as well as F9 to run through debugging quickly
Powered by ComboStrap