View Issue Details

IDProjectCategoryView StatusLast Update
0001476XdebugUncategorizedpublic2017-10-05 12:33
Reporterkriyate Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
Product Version2.5.5 
Summary0001476: error evaluating code errors in REPL
Description

Hi there:

I am Xdebug via Felix Becker's PHP Debug extension (https://github.com/felixfbecker/vscode-php-debug) for Visual Studio Code 1.16.1. I'm connecting to XDebug just fine, can set breakpoints and view variables in the debug pane without any issues.

However, I am consistently getting error evaluating code when attempting to type any PHP statements or expressions in the debug console. The developer assures me this is a problem on the part of Xdebug, and not his extension.

My question is what kind of PHP commands can I send to the REPL? 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

I'm a little confused because I thought I could use any valid PHP command in the console, similar to PHPStorm's console.

Thanks.

Steps To Reproduce

type the following into debug console after launching a debug session:

function foo() {}
Additional Information

Note: duplicate of my Stack Exchange question

My error: https://i.stack.imgur.com/HqZeP.png

PHP version: 7.1.8
XDebug version: 2.5.5
Adapter version: 1.11.1

Your launch.json:

    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "log": false,
            "localSourceRoot": "${workspaceRoot}/public"
        }
    ]
}

XDebug php.ini config:

zend_extension=/usr/local/bin/xdebug.so

[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1

XDebug logfile (from setting xdebug.remote_log in php.ini):

<- eval -i 21 -- ZWNobyAieWVzIg==
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="21" status="break" reason="ok"><error code="206"><message><![CDATA[error evaluating code]]></message></error></response>

Adapter logfile (from setting "log": true in launch.json):

function foo() {}
error evaluating code
-> evaluateRequest
{ command: 'evaluate',
  arguments: { expression: 'function foo() {}', frameId: 66, context: 'repl' },
  type: 'request',
  seq: 21 }
<- evaluateResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 21,
  command: 'evaluate',
TagsNo tags attached.
Operating SystemOS X 10.12.6
PHP Version7.1.0-7.1.4

Activities

derick

2017-10-04 09:58

administrator   ~0004434

In order for this to work, you need to use correct PHP syntax.

From your image, the 3 foreach'es are all incorrect syntax, as the last var_dump()'s ; is missing. This doesn't work in PHP:

derick@singlemalt:~ $ php
<?php
foreach($archives as $key => $val) { var_dump($key); var_dump($val) }
?>

Parse error: syntax error, unexpected '}' in - on line 2

The error from your log:

<- eval -i 21 -- ZWNobyAieWVzIg==
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" [^] command="eval" transaction_id="21" status="break" reason="ok"><error code="206"><message><![CDATA[error evaluating code]]></message></error></response>

is correct too, as ZWNobyAieWVzIg== translates to echo "yes", which is missing its ; at the end:

derick@singlemalt:~ $ php -r "eval(base64_decode('ZWNobyAieWVzIg=='));"

Parse error: syntax error, unexpected end of file, expecting ',' or ';' in Command line code(1) : eval()'d code on line 1

And declaring functions and classes do not return a value.

kriyate

2017-10-05 12:33

reporter   ~0004435

Hi Derick:
ok, thanks a lot for looking into this and answering my question. Your work is much appreciated. Cheers.

Issue History

Date Modified Username Field Change
2017-10-03 21:58 kriyate New Issue
2017-10-04 09:58 derick Note Added: 0004434
2017-10-04 09:58 derick Status new => resolved
2017-10-04 09:58 derick Resolution open => no change required
2017-10-04 09:58 derick Assigned To => derick
2017-10-05 12:33 kriyate Note Added: 0004435
2020-03-12 16:35 derick Category Usage problems (Wrong Results) => Variable Display
2020-03-12 16:38 derick Category Variable Display => Uncategorized