29
loading...
This website collects cookies to deliver better user experience
Just the Gist
On December 13th we peeked at variables with the help of a different built-in functions. But there are more powerful ways you can debug your code. Xdebug is a debugging extension for PHP. It will let you glimpse all the variables and their values at the breakpoint of your choosing. You can then step through the execution of your code, line by line if you want. Today we will see how to install and use Xdebug in VSCode.
Correction: Previous version stated that Xdebug would listen for requests when PHP is executed. Instead it's that an IDE, or in this case the plugin in VSCode, that listens and then Xdebug makes a connection to it.
php -v
. If you are on the latest PHP thread safe version it could look like this (if you use a non-thread safe version you would see NTS instead of ZTS):PHP 8.1.0 (cli) (built: Nov 23 2021 21:48:28) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
with Zend OPcache v8.1.0, Copyright (c), by Zend Technologies
php.ini
file. Find zend_extension=opcache
(if you have it) and below it add zend_extension=xdebug
. php.ini
file, we are going to add the following lines:xdebug.mode = debug
xdebug.start_with_request = yes
yes
to no
if you don't want to run xdebug whenever you execute PHP code.)php -v
again, you should now see xdebug listed below your PHP version.PHP Debug
by Felix Becker. Search for php-debug
in the VSCode marketplace and install it. Then click on the play-button with a bug on it.var_dump
.