【问题标题】:Methods for an Xdebug Exception classXdebug Exception 类的方法
【发布时间】:2014-07-14 15:33:57
【问题描述】:

是否可以看到 Xdebug 创建的扩展异常类的方法?我想获取 HTML 格式的堆栈跟踪。

【问题讨论】:

    标签: php xdebug


    【解决方案1】:

    所以在破解它之后,没有像 Niels 展示的方法,但是有一个名为 $exception->xdebug_message 的公共属性,它具有 HTML 格式的消息。如果您将其放在 HTML 页面中,请不要忘记将其包装在 table 标记中。

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

    【讨论】:

      【解决方案2】:

      要获得精美的 HTML 输出跟踪:

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

      传递选项XDEBUG_STACK_NO_DESC 以省略标题。

      但是,Xdebug 实际上并没有将可见方法修补到 Exception 中,这可以通过在异常处理程序中打印 get_class_methods($e) 来证明:

      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)
      

      当然,您始终可以根据getTrace 返回的数组自行格式化它,但它有nothing to do with Xdebug and is just built in functionality

      【讨论】:

      • 我在看那个,但那个调用并没有给我来自异常的信息。我正在捕获未处理的异常,我想在异常发生时获取堆栈。
      • 请记住,xdebug_print_function_stack() 的选项仅在 Xdebug 2.3 之后可用。 (那个版本甚至发布了吗?)xdebug.org/docs/stack_trace#xdebug_print_function_stack
      猜你喜欢
      • 2015-02-15
      • 2012-05-17
      • 2012-04-06
      • 1970-01-01
      • 1970-01-01
      • 2020-01-16
      • 1970-01-01
      • 2011-12-30
      • 2015-12-05
      相关资源
      最近更新 更多