xdebug / vscode-php-debug

PHP Debug Adapter for Visual Studio Code 🐞⛔
MIT License
785 stars 177 forks source link

Incorrect Watch Value for Array vs Object Access in Xdebug #976

Open stgpepper opened 3 weeks ago

stgpepper commented 3 weeks ago

PHP version: 8.2 Xdebug version: 3.3.1 VS Code extension version: v1.35.0

Your launch.json:

    "version": "0.2.0",
    "configurations": [
        {
            "name": "Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/var/www/html/": "${workspaceFolder}/src/"
            },
            "log": false
        },
    ]
}

Xdebug php.ini config: -

Xdebug logfile (from setting xdebug.log in php.ini): - VS Code extension logfile (from setting "log": true in launch.json): -

Code snippet to reproduce:

$myarr['myval'] = "test";
echo $myarr['myval']."\n";
echo $myarr->myval;

I added two watch expressions:

$myarr['myval'] $myarr->myval Both watches incorrectly show the value "test", even though only the array access $myarr['myval'] is valid and the object access $myarr->myval should be null or result in an error. image

zobo commented 3 weeks ago

I'll do a quick test to see if this "issue" is part of Xdebug or the plugin.

zobo commented 2 weeks ago

Hi. Sorry for the late reply. This does not present here. PHP 8.2.8 Xdebug: 3.4.0-alpha

image

-> evaluateRequest
{ command: 'evaluate',
  arguments: { expression: "$myarr['myval']", frameId: 1, context: 'watch' },
  type: 'request',
  seq: 11 }

xd(1) <- eval -i 12 -- JG15YXJyWydteXZhbCdd
xd(1) -> <?xml version="1.0" encoding="iso-8859-1"?><response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="12"><property type="string" size="4" encoding="base64"><![CDATA[dGVzdA==]]></property></response>

<- evaluateResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 11,
  command: 'evaluate',
  success: true,
  body: { result: '"test"', variablesReference: 0 } }

and

-> evaluateRequest
{ command: 'evaluate',
  arguments: { expression: '$myarr->myval', frameId: 1, context: 'watch' },
  type: 'request',
  seq: 12 }

xd(1) <- eval -i 13 -- JG15YXJyLT5teXZhbA==
xd(1) -> <?xml version="1.0" encoding="iso-8859-1"?><response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="13"><property type="null"></property></response>
<- evaluateResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 12,
  command: 'evaluate',
  success: true,
  body: { result: 'null', variablesReference: 0 } }

Please repeat your test and set log to true and attack the whole output in Debug Console.