Search code examples
phpvisual-studioxdebug

Visual Studio, PHP, Xdebug: Error evaluating code while debugging


My Visual Studio debugger is not working properly and I get "Error evaluating code" for everything (see the variable value, 1+1, and any other PHP code). All fixes are not working.

I tried with:

VS 2017/2019/2022

PHP 7.4, PHP8.0, PHP 8.1, PHP 8.2

I tried multiple configurations of php.ini

I'm using XAMPP 3.3.0 on W10.

Xdebug log show errors like this when I try to run any PHP code in the immediate window:

[8796] [Step Debug] <- eval -i 16-0 -- ZXZhbCgidHJ5IHsgcmV0dXJuICAxICsgMTsgfWNhdGNoIChUaHJvd2FibGUgJHQpeyByZXR1cm4gbmV3IERldnNlbnNlRXZhbEVycm9yKCR0LT5nZXRNZXNzYWdlKCkpO31jYXRjaCAoRXhjZXB0aW9uICRlKXsgcmV0dXJuIG5ldyBEZXZzZW5zZUV2YWxFcnJvcigkZS0+Z2V0TWVzc2FnZSgpKTt9Iik7
[8796] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="16-0" status="break" reason="ok"><error code="206"><message><![CDATA[error evaluating code]]></message></error></response>

I'm trying to solve this issue by 1 year. No success.


Solution

  • The base64 decode of that string results in:

    eval("try { return  1 + 1; }catch (Throwable $t){ return new DevsenseEvalError($t->getMessage());}catch (Exception $e){ return new DevsenseEvalError($e->getMessage());}");
    

    Which can't really work, as you haven't escaped the $t in catch (Throwable $t) for example, and that throws a warning and a parse error when you run this with normal PHP:

    Warning: Undefined variable $t in /tmp/foo.php on line 2
    
    Warning: Undefined variable $t in /tmp/foo.php on line 2
    
    Warning: Attempt to read property "getMessage" on null in /tmp/foo.php on line 2
    
    Warning: Undefined variable $e in /tmp/foo.php on line 2
    
    Warning: Undefined variable $e in /tmp/foo.php on line 2
    
    Warning: Attempt to read property "getMessage" on null in /tmp/foo.php on line 2
    
    Parse error: syntax error, unexpected token ")" in /tmp/foo.php(2) : eval()'d code on line 1
    

    It seems likely that Devsense (I don't know what that is) is throwing a spanner in the works, as it literally just should send MSsx (base 64 encoded form of 1+1).