MantisBT

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001476XdebugUsage problems (Wrong Results)public2017-10-03 22:582017-10-05 13:33
Reporterkriyate 
Assigned Toderick 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionno change required 
PlatformOSOS Version
Product Version2.5.5 
Target VersionFixed in Version 
Summary0001476: `error evaluating code` errors in REPL
DescriptionHi 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 Reproducetype the following into debug console after launching a debug session:

```
function foo() {}
```
Additional InformationNote: duplicate of my [Stack Exchange question](https://stackoverflow.com/questions/46551771/is-visual-studio-codes-php-debug-console-interactive [^])

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
Attached Files

- Relationships

-  Notes
(0004434)
derick (administrator)
2017-10-04 10:58

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.
(0004435)
kriyate (reporter)
2017-10-05 13:33

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 22:58 kriyate New Issue
2017-10-04 10:58 derick Note Added: 0004434
2017-10-04 10:58 derick Status new => resolved
2017-10-04 10:58 derick Resolution open => no change required
2017-10-04 10:58 derick Assigned To => derick
2017-10-05 13:33 kriyate Note Added: 0004435


Copyright © 2000 - 2017 MantisBT Team
Powered by Mantis Bugtracker