回溯中缺少例外的args

时间:2009-09-29 13:02:17

标签: php

当我在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)[“function”] => string(4)“test”}}

我正在运行PHP 5.2.8。

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

3 个答案:

答案 0 :(得分:1)

很奇怪。

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

<?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());
}
?>

答案 1 :(得分:1)

我刚刚在我的本地安装上试过它,它看起来确实有所提升,虽然我运行的是5.3 atm ......

它仍然应该至少提供一个空数组,即使没有传递参数......

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

答案 2 :(得分:0)

我尝试升级到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());
    }
}

感谢您的帮助!