Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Visual Studio Code's PHP debug console interactive?

I am using Visual Studio Code 1.16.1 together with Felix Becker's PHP Debug extension. I'm connecting to XDebug just fine, can set breakpoints and view variables in the debug pane without any issues.

However, the debug console seems kind of useless, I can only run super basic PHP commands, and I can't seem to evaluate normal PHP commands or interact with my app very well.

I consistently get error evaluating code when attempting to type any PHP statements or expressions in the debug console. It seems like all I am able to do is declare variables, arrays, and objects.

I can't declare classes, functions, use control structures (if, foreach, etc.).

Works:

$x = 4
//4

$x
//4

$x = new stdClass();
//stdClass

$x = [];
//array(0)

($x) ? yes : no
// yes

(!$x) ? yes : no
// no

preg_replace('/dog/', 'cat', 'The quick brown fox jumps over the lazy dog.')
// "The quick brown fox jumps over the lazy cat."

request()
//Illuminate\Http\Request (Laravel helper methods work)

Doesn't Work:

echo "yes"
//error evaluating code

if ($x == 4) { echo "yes" }
//error evaluating code

for ($i=0; $i < 5; $i++) { }
//error evaluating code

function foo() {}
//error evaluating code

class SimpleClass {}
//error evaluating code

$var_dump($x)
//null

Is the debug console supposed to act like a true REPL? I know PHPStorm's console can evaluate any PHP you throw at it, can Visual Studio Code do the same? Is anyone else facing this problem?

Thanks.

enter image description here

like image 342
JP Lew Avatar asked Sep 07 '25 11:09

JP Lew


1 Answers

TL;DR; It's an XDebug related issue, not related to OP's extension, and canceling the watch variables may fix XDebug behaviour.


The issue is not related to OP's extension, it's an XDebug related issue.

Many people workaround this issue, by removing the variables from VSCode's "Watch" list, in the debug view.

In following screenshot, the red arrow indicates a button where you can delete all watch-expressions with once click:

VSCode's watch variable section

See also: github.com/xdebug/vscode-php-debug/issues/192

like image 149
Top-Master Avatar answered Sep 09 '25 04:09

Top-Master