|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-08-22 21:52 UTC] jmcgraw1 at gmail dot com
Description:
------------
Throwing an exception within set_error_handler() produces an exception which produces a messed up backtrace. Each entry within the backtrace contains the 'args' for the previous call, with the most immediate entry missing its 'args'. In the case of my example below the string 'foobar' should be in the array 'args' for the call to B(), not A().
Reproduce code:
---------------
function handle_errors() {
throw new ErrorException();
}
set_error_handler('handle_errors', E_ALL);
function A() {
$foo->bar; // Purposely cause error
}
function B($c) {
A();
}
try {
B('foobar');
} catch (Exception $e) {
var_dump($e->getTrace());
}
Expected result:
----------------
array(3) {
[0]=>
array(4) {
["file"]=>
string(42) "/home/public/pdt/framework/html/error.php"
["line"]=>
int(10)
["function"]=>
string(13) "handle_errors"
["args"]=>
array(0) {
}
}
[1]=>
array(4) {
["file"]=>
string(42) "/home/public/pdt/framework/html/error.php"
["line"]=>
int(14)
["function"]=>
string(1) "A"
}
[2]=>
array(3) {
["file"]=>
string(42) "/home/public/pdt/framework/html/error.php"
["line"]=>
int(18)
["function"]=>
string(1) "B"
["args"]=>
array(1) {
[0]=>
string(6) "foobar"
}
}
}
Actual result:
--------------
array(3) {
[0]=>
array(4) {
["file"]=>
string(42) "/home/public/pdt/framework/html/error.php"
["line"]=>
int(10)
["function"]=>
string(13) "handle_errors"
["args"]=>
array(0) {
}
}
[1]=>
array(4) {
["file"]=>
string(42) "/home/public/pdt/framework/html/error.php"
["line"]=>
int(14)
["function"]=>
string(1) "A"
["args"]=>
array(1) {
[0]=>
string(6) "foobar"
}
}
[2]=>
array(3) {
["file"]=>
string(42) "/home/public/pdt/framework/html/error.php"
["line"]=>
int(18)
["function"]=>
string(1) "B"
}
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 09:00:01 2025 UTC |
PHP 5.2.6 (cli) (built: May 8 2008 16:50:48) Output: array(3) { [0]=> array(4) { ["file"]=> string(26) "/home/jmcgraw/test_old.php" ["line"]=> int(10) ["function"]=> string(13) "handle_errors" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(26) "/home/jmcgraw/test_old.php" ["line"]=> int(14) ["function"]=> string(1) "A" ["args"]=> array(1) { [0]=> string(6) "foobar" } } [2]=> array(3) { ["file"]=> string(26) "/home/jmcgraw/test_old.php" ["line"]=> int(18) ["function"]=> string(1) "B" } } PHP 5.2.7-dev (cli) (built: Aug 27 2008 12:47:06) Output: array(3) { [0]=> array(4) { ["file"]=> string(22) "/home/jmcgraw/test_new.php" ["line"]=> int(10) ["function"]=> string(13) "handle_errors" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(22) "/home/jmcgraw/test_new.php" ["line"]=> int(14) ["function"]=> string(1) "A" ["args"]=> array(1) { [0]=> string(6) "foobar" } } [2]=> array(3) { ["file"]=> string(22) "/home/jmcgraw/test_new.php" ["line"]=> int(18) ["function"]=> string(1) "B" } } Result: Latest snapshot does NOT solve problem.