Exceptions missing arguments in backtrace

When I run the example code http://us2.php.net/manual/en/exception.gettrace.php , I am not getting "args" in the backtrace as in the example output.

Is this a PHP bug or am I missing something?

My conclusion:

array (1) {[0] => array (3) {["file"] => string (25) "D: \ www \ project \ index.php" ["line"] => int (79) [ "function"] => string (4) "test"}}

I am running PHP 5.2.8.

Change: . The output of the example is to run the PHP.net example code with or without function arguments.

+2


source to share


3 answers


I tried to upgrade to PHP 5.2.9 (XAMPP 1.7.1) but it didn't work. But when I tried to work in linux environment with PHP 5.2.11 it worked. I have posted the complete test code below.

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

      



Thank you for your help!

0


source


A bit weird.

The next (class) does work, but ... But it should still give arguments, even if you overload it with a nomenclature function.



<?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


source


I just tried this on my local installation and it seems to work like advanced, even though I'm running 5.3 atm ...

It still needs to contain at least an empty array, even if no arguments are passed ...

try googling for a bug on your specific PHP version or search php.net bug tracker

+1


source







All Articles