Methods for an Xdebug Exception class

2019-03-02 03:18发布

问题:

Is it possible to see the methods of the extended Exception class Xdebug creates? I want to get at the HTML formatted stack trace.

回答1:

So after hacking at it, there's no method like Niels showed but there's a public property called $exception->xdebug_message that has the HTML formatted message. Don't forget to wrap it in a table tag if you are placing it in a HTML page.

echo '<table>';
echo $exception->xdebug_message;
echo '</table>';


回答2:

To get the fancy HTML outputted trace:

ob_start();
xdebug_print_function_stack();
$myFancyHTMLOutput = ob_get_clean();

Pass the option XDEBUG_STACK_NO_DESC to leave out the header.

However, Xdebug does not actually patch visible methods into Exception, as evidenced by printing get_class_methods($e) inside an exception handler:

array (size=9)
  0 => string '__construct' (length=11)
  1 => string 'getMessage' (length=10)
  2 => string 'getCode' (length=7)
  3 => string 'getFile' (length=7)
  4 => string 'getLine' (length=7)
  5 => string 'getTrace' (length=8)
  6 => string 'getPrevious' (length=11)
  7 => string 'getTraceAsString' (length=16)
  8 => string '__toString' (length=10)

You can of course always format it yourself from the array returned by getTrace, but that has nothing to do with Xdebug and is just built in functionality.



标签: php xdebug