php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34175 debug_backtrace shows wrong arguments when called from an own error handler
Submitted: 2005-08-17 18:27 UTC Modified: 2005-08-22 17:41 UTC
From: flummi at everymail dot net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.4 OS: Redhat Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
46 - 3 = ?
Subscribe to this entry?

 
 [2005-08-17 18:27 UTC] flummi at everymail dot net
Description:
------------
When calling debug_backtrace from an own error handler, it provides a different output than when calling it directly. As you can see in the code, I have two calls to debug_backtrace, one from my error handler, the other from a function. As I raise an error shortly after calling debug_backtrace the first time, I would expect to have the same first few entries in the debug_backtrace array. I.e. the last entry shows an error on line 18, where the function 'a_test' is called with arg 'another friend'. In real this function is called with the arg 'friend' (arg 'another friend' is used in the next function call.
I hope I could explain the bug good enough as my natural language is german. :-)

Reproduce code:
---------------
<pre>
<?php
function HandleError($n, $m, $f, $l){
  print_r(debug_backtrace());
}
set_error_handler('HandleError');
function a_test($str)
{
   echo "\nHi: $str";
   b_test("another friend");
}
function b_test($str2)
{
   echo "\nHi $str2";
   print_r(debug_backtrace());
   echo "now raise an error..".(2/0);
}
a_test('friend');
?>
</pre>


Expected result:
----------------
Hi: friend
Hi another friendArray
(
    [0] => Array
        (
            [file] => /var/www/html/xiview/test/testerror2.php
            [line] => 10
            [function] => b_test
            [args] => Array
                (
                    [0] => another friend
                )

        )

    [1] => Array
        (
            [file] => /var/www/html/xiview/test/testerror2.php
            [line] => 18
            [function] => a_test
            [args] => Array
                (
                    [0] => friend
                )

        )

)
Array
(
    [0] => Array
        (
            [file] => /var/www/html/xiview/test/testerror2.php
            [line] => 16
            [function] => HandleError
        )

    [1] => Array
        (
            [file] => /var/www/html/xiview/test/testerror2.php
            [line] => 16
            [function] => b_test
        )

    [2] => Array
        (
            [file] => /var/www/html/xiview/test/testerror2.php
            [line] => 10
            [function] => b_test
            [args] => Array
                (
                    [str2] => another friend
                )

        )

    [3] => Array
        (
            [file] => /var/www/html/xiview/test/testerror2.php
            [line] => 18
            [function] => a_test
            [args] => Array
                (
                    [0] => friend
                )

        )

)

Actual result:
--------------
Hi: friend
Hi another friendArray
(
    [0] => Array
        (
            [file] => /var/www/html/xiview/test/testerror2.php
            [line] => 10
            [function] => b_test
            [args] => Array
                (
                    [0] => another friend
                )

        )

    [1] => Array
        (
            [file] => /var/www/html/xiview/test/testerror2.php
            [line] => 18
            [function] => a_test
            [args] => Array
                (
                    [0] => friend
                )

        )

)
Array
(
    [0] => Array
        (
            [file] => /var/www/html/xiview/test/testerror2.php
            [line] => 16
            [function] => HandleError
        )

    [1] => Array
        (
            [file] => /var/www/html/xiview/test/testerror2.php
            [line] => 16
            [function] => b_test
        )

    [2] => Array
        (
            [file] => /var/www/html/xiview/test/testerror2.php
            [line] => 10
            [function] => b_test
            [args] => Array
                (
                    [0] => 2
                    [1] => Division by zero
                    [2] => /var/www/html/xiview/test/testerror2.php
                    [3] => 16
                    [4] => Array
                        (
                            [str2] => another friend
                        )

                )

        )

    [3] => Array
        (
            [file] => /var/www/html/xiview/test/testerror2.php
            [line] => 18
            [function] => a_test
            [args] => Array
                (
                    [0] => another friend
                )

        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-17 18:59 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-08-22 16:23 UTC] flummi at everymail dot net
I just tried the latest development version (php5-200508221230) - here it seems to work quite well, so the bug can be closed, as I can say. Thanx!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 07:01:32 2024 UTC