vscode-php-debug icon indicating copy to clipboard operation
vscode-php-debug copied to clipboard

Evaluate namespaces in debug console

Open jeffam opened this issue 1 year ago • 1 comments

PHP version: 8.2.15 Xdebug version: 3.2.0 VS Code extension version: 1.34.0

When I test expressions in the debug console, I've noticed that namespaced classes don't seem to evaluate use statements.

For example, if I debug this code:

<?php

require '../vendor/autoload.php';

use XdebugNsTest\Bar;

$test = new Bar('Hello, World!');

var_dump($test instanceof Bar);

And enter the following in the debug console:

→  $test
 ❯ XdebugNsTest\Bar
→  $test instanceof Bar
   false
→  $test instanceof XdebugNsTest\Bar
   true

$test instanceof Bar returns false when I would expect it to return true.

jeffam avatar Jan 25 '24 18:01 jeffam

Indeed that is the current way, as all code in the debug window is just passed to Xdebug eval command. And this is probably as it is in PHP as I believe use referencing happens in compile time and not run-time.

This is also something that's bothering me sometimes but I can hardly do much as it would require that this extension understood a lot more about PHP language as it does...

zobo avatar Apr 02 '24 07:04 zobo