Debugging a PHP application can involve quite a bit of machinery, and effort getting that machinery setup. But it's worth it because what alternative is there? echo? Come on!

Thanks to Derick Rethans, XDebug can do a ton of cool things for you. For example, it overloads var_dump() and gives you control over how you want deeply nested data structures to be displayed.

We did an old deep dive using NetBeans and XDebug on a complex CiviCRM mailer embedded as a module in Drupal

A more current setup would be debugging Semantic MediaWiki in a Docker container using VSCode with PHPDebug.

XDebug with VSCode edit

Be sure to install the PHP Debug extension, and read the documentation on that page thoroughly.

Install edit

Ensure that XDebug extension is installed for your PHP environment.

in the console, you can just type php -v which will tell you not just the version of PHP, but also whether XDebug is enabled. More specifically, you could php -r 'echo phpversion("xdebug");'

You should also check the settings of your installation by looking at the ini file for XDebug
php --ini shows you the ini files that are loaded for your PHP. Inspect the one related to XDebug and ensure that it is set for Debugging.

cat /etc/php/8.3/cli/conf.d/99-xdebug.ini

zend_extension=xdebug
xdebug.mode=coverage,develop,debug,profile,trace

Beware that although the mode is critical and can only be set in the ini file, that setting can be overridden by the environment variable XDEBUG_MODE - so look for that in container-driven setups.

Configuration Report edit

Create a file like info.php on your development host, and then browse it for a full report of your Debugging environment.

# choose a target
myFile='../../info.php';
# add the phpinfo() function
echo -e "<?php \nphpinfo();\n" > $myFile;
# add the xdeub_info() function
echo -e "\n\nxdebug_info();\n" >> $myFile;

Step Debugging edit

Covered at https://xdebug.org/docs/step_debug