xdebug Cheatsheet

disable xdebug html output

  • ini_set('html_errors', false);

Enable file_link

Example for PHPStorm and PHP7.4 @ Ubuntu

  • apt install php7.4-xdebug
  • vi /etc/php/7.4/mods-available/xdebug.ini
    • xdebug.file_link_format="phpstorm://open?file=%f&line=%l"
  • systemctl restart apache

Furthermore configure the url handler in PHPStorm

Open files from webbrowser exceptions directly in PhpStorm

https://github.com/aik099/PhpStormProtocol
https://github.com/sanduhrs/phpstorm-url-handler

  • cd ~/Downloads
  • git clone https://github.com/sanduhrs/phpstorm-url-handler
  • cd phpstorm-url-handler
  • ln -s ~/bin/PhpStorm-232.9559.64/bin/phpstorm.sh ~/bin/phpstorm
    • Make available in $PATH
  • cp -a phpstorm-url-handler ~/bin/
  • sudo desktop-file-install phpstorm-url-handler.desktop
  • sudo update-desktop-database

php var_dump() limits the number of levels

Problem:

php var_dump() limits the number of levels to three.

 

Solution:

This is the default setting of xdebug.

 

To change the default, edit your xdebug.ini file and add the folllowing line:
xdebug.var_display_max_depth=n

 

Ubuntu:

  • sudo vi /etc/php5/conf.d/xdebug.ini
  • or
  • sudo vi /etc/php/7.0/mods-available/xdebug.ini
    • xdebug.var_display_max_depth = 15 
  • sudo apache2ctl restart

 

Moreover:

  • e.g. cut off string:
    • xdebug.var_display_max_data = 4096
  • heavily nested:
    • xdebug.max_nesting_level = 200