xdebug / vscode-php-debug

PHP Debug Adapter for Visual Studio Code 🐞⛔
MIT License
763 stars 178 forks source link

Xdebug values viewer not showing float value as float (if it's round)! #962

Closed AndreyChursin closed 1 week ago

AndreyChursin commented 1 month ago

PHP version: 8.1.28 Xdebug version: v3.3.2 VS Code extension version: v1.34.0

Your launch.json:

{
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "xdebugSettings": {
                "max_children": 1000,
            },
            "pathMappings": {
                "/var/www": "${workspaceFolder}" 
            },
}

Xdebug php.ini config:

xdebug.mode = develop,trace,debug
xdebug.start_with_request = trigger
xdebug.discover_client_host = true
xdebug.client_host = host.docker.internal
xdebug.client_port = 9003

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

Code snippet to reproduce:

$itsShouldBeFloatValue = \floatval("10.00"); // in "variables" sidebar 'itsShouldBeFloatValue' will be shown as '10'
echo \is_int($itsShouldBeFloatValue) 
     ? '$itsShouldBeFloatValue is int' 
     : '$itsShouldBeFloatValue is not int';

But if:


$itsShouldBeFloatValue = \floatval("10.02"); // in "variables" sidebar 'itsShouldBeFloatValue' will be shown as '10.02'
zobo commented 1 month ago

Hi. Can you please reproduce the issue wile having log:true in your launch.json configuration and attach the log from Debug Console. This will show what data is transferred and we can check where the problem comes from.

zobo commented 1 week ago

I tried the code you offered here and here is the raw communication between Xdebug and VScode

Xdebug reports the $itsShouldBeFloatValue variable as type float and value 10.

xd(1) -> <?xml version="1.0" encoding="iso-8859-1"?><response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="12" context="0">
<property name="$itsShouldBeFloatValue" fullname="$itsShouldBeFloatValue" type="float">
<![CDATA[10]]></property></response>

This is also how I pass it to VSCode.

<- variablesResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 13,
  command: 'variables',
  success: true,
  body:
   { variables:
      [ { name: '$itsShouldBeFloatValue',
          value: '10',
          type: 'float',
          variablesReference: 0,
          presentationHint: {},
          evaluateName: '$itsShouldBeFloatValue',
          indexedVariables: undefined } ] } }

The float gets shown on variable hover. image

Now, I could reformat the value if it's float to 10.0, but then again PHP internally does not do that it seems:

var_dump($itsShouldBeFloatValue);
echo $itsShouldBeFloatValue;
echo "\n";

Output:

double(10)
10

I'll close this as I believe it works as it should, but feel free to reopen it with some reference to why this should be different.

Best!