tags:

views:

64

answers:

3

When I run the example code at http://us2.php.net/manual/en/exception.gettrace.php I get no "args" in the backtrace, as there is in the example output.

Is this a PHP bug or am I missing something?

My output:

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.

Edit: The example output is from running the PHP.net's example code, with or without arguments to the function.

+1  A: 

Hmm weird.

The following (a class) does work though... But it still should give the args, even if you overload it to a nomral 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());
}
?>
Deefjuh
+1  A: 

I've just tried it on my local installation, and it does seem to work as promoted, although i'm running 5.3 atm...

It still should give at least an empty array, even if no arguments are passed...

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

Nicky De Maeyer
A: 

I tried to upgrade to PHP 5.2.9 (XAMPP 1.7.1), but it didn't work. But when I tried on a linux environment running PHP 5.2.11, it did work. I 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());
    }
}

Thanks for all your help!

Znarkus
Ok thnx, thought I was going crazy, but it was a bug after all...
Deefjuh