【问题标题】:Exceptions are missing args in backtrace异常在回溯中缺少 args
【发布时间】:2009-09-29 13:02:16
【问题描述】:

当我在http://us2.php.net/manual/en/exception.gettrace.php 运行示例代码时,我在回溯中没有得到“args”,就像示例输出中一样。

这是一个 PHP 错误还是我遗漏了什么?

我的输出:

array(1) { [0]=> array(3) { ["file"]=> string(25) "D:\www\project\index.php" ["line"]=> int( 79) ["函数"]=> 字符串(4) "测试" } }

我正在运行 PHP 5.2.8。

编辑:示例输出来自运行 PHP.net 的示例代码,函数带有或不带有参数。

【问题讨论】:

  • 能插入引发异常的代码吗?
  • @Znarkus 再次阅读问题,正在使用的代码是 OP 链接的示例页面上的代码。
  • 如果将参数传递给函数会发生什么?
  • 是的,代码是来自 php.net 的示例代码。如果我将参数传递给函数没有任何反应,我仍然会得到上面的输出。

标签: php


【解决方案1】:

嗯,很奇怪。

以下(一个类)确实有效......但它仍然应该给出参数,即使你将它重载到一个正常的函数。

<?php
class Test{
    function __construct($arg){
        $this->test($arg);
    }
    function test($args) {
     throw new Exception;
    }
}

try {
    new Test('Yar');
} catch(Exception $e) {
//print_r(debug_backtrace());
 var_dump($e->getTrace());
}
?>

【讨论】:

    【解决方案2】:

    我刚刚在我的本地安装上尝试过它,它似乎确实像提升的那样工作,虽然我运行的是 5.3 atm...

    它仍然应该至少给出一个空数组,即使没有传递任何参数...

    尝试使用谷歌搜索特定 PHP 版本的错误,或搜索 php.net bug tracker

    【讨论】:

      【解决方案3】:

      我尝试升级到 PHP 5.2.9 (XAMPP 1.7.1),但没有成功。但是当我在运行 PHP 5.2.11 的 linux 环境中尝试时,它确实有效。我在下面发布了完整的测试代码。

      <?php
      
      error_reporting(E_ALL | E_STRICT);
      header('Content-type: text/plain; charset=utf-8');
      
      function a($a) {
          throw new Exception2('EXCEPTION MESSAGE');
      }
      
      function b($b) {
          a($b);
      }
      
      try {
          b('THIS PARAMETER SHOULD SHOW UP');
      } catch(Exception $e) {
          var_dump($e);
      }
      
      
      class Exception2 extends Exception
      {
          public function __construct()
          {
              $args = func_get_args();
              call_user_func_array(array($this, 'parent::__construct'), $args);
      
              var_dump(debug_backtrace());
          }
      }
      

      感谢您的帮助!

      【讨论】:

        猜你喜欢
        • 2017-11-10
        • 1970-01-01
        • 2020-09-13
        • 2015-06-06
        • 2016-02-09
        • 2010-12-03
        • 1970-01-01
        • 2010-10-17
        • 2020-01-05
        相关资源
        最近更新 更多