View Issue Details

IDProjectCategoryView StatusLast Update
0001907XdebugUncategorizedpublic2020-12-11 11:18
Reporternicolas-grekas Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.9.8 
Fixed in Version3.0.2 
Summary0001907: Empty exception message when setting the $message property to a stringable object
Description

As hinted in https://github.com/symfony/symfony/pull/39196, xdebug changes the behavior of PHP when the Exception::$message property is set to a stringable object.

The following script yields an empty output when run with xdebug enabled, and echoes 'Hello World' on PHP (all versions >=7.0).
See https://3v4l.org/RGM4p

<?php

class LazyException extends Exception
{
public function construct()
{
parent::
construct();

    $this->message = new class() {
        public function __toString()
        {
            return 'World';
        }
    };
}

}

$e = new LazyException();

try {
throw $e;
} catch (\Exception $e) {
echo 'Hello ';
echo $e->getMessage();
echo "\n";
}
?>

TagsNo tags attached.
Operating System
PHP Version7.4.0-7.4.4

Activities

nicolas-grekas

2020-12-08 11:32

reporter   ~0005574

I suppose this happens because the code in src/develop/stack.c tries to populate the "xdebug_message" property, but doesn't handle objects there.

A simple fix could be to cast the object to string, but this would break the laziness property.
Another fix might be to NOT populate the "xdebug_message" when a message is an object.
Or another way :)

derick

2020-12-11 10:57

administrator   ~0005582

https://github.com/xdebug/xdebug/pull/708

Issue History

Date Modified Username Field Change
2020-12-07 18:31 nicolas-grekas New Issue
2020-12-08 11:32 nicolas-grekas Note Added: 0005574
2020-12-10 16:34 derick Assigned To => derick
2020-12-10 16:34 derick Status new => confirmed
2020-12-11 10:57 derick Note Added: 0005582
2020-12-11 11:18 derick Status confirmed => closed
2020-12-11 11:18 derick Resolution open => fixed
2020-12-11 11:18 derick Fixed in Version => 3.0.2