|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-04-27 15:18 UTC] Jared dot Williams1 at ntlworld dot com
Description:
------------
The call stack trace includes the name of the function used to map PHP errors to exceptions. And as getTrace() is marked as final, cannot override to exclude this.
Reproduce code:
---------------
<?php
function errorToExceptionHandler($severity, $message, $file, $line)
{
if (error_reporting() & $severity)
throw new ErrorException($message, 0, $severity, $file, $line);
}
error_reporting(E_ALL & ~(E_NOTICE|E_USER_NOTICE));
set_error_handler('errorToExceptionHandler');
try
{
$a = 1 / 0;
}
catch (ErrorException $e)
{
var_dump($e->getTrace());
}
catch (ErrorException $e)
{
var_dump($e->getTrace());
}
Expected result:
----------------
array
0 =>
array
'file' => 'C:\Inetpub\Framework\www\bug.php' (length=32)
'line' => 14
Actual result:
--------------
array
0 =>
array
'file' => 'C:\Inetpub\Framework\www\bug.php' (length=32)
'line' => 14
'function' => 'errorToExceptionHandler' (length=23)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 12:00:01 2025 UTC |
But more investigation, and it appears that something alters the trace. As args for the [0] element of the trace a what would be expected. Eg: <?php function errorToExceptionHandler($severity, $message, $file, $line) { if (error_reporting() & $severity) throw new ErrorException($message, 0, $severity, $file, $line); } error_reporting(E_ALL & ~(E_NOTICE|E_USER_NOTICE)); set_error_handler('errorToExceptionHandler'); function divr($a, $b) { if ($b >= 1) return divr($a, $b >> 1); return $a / $b; } try { divr(1024, 2); } catch (ErrorException $e) { var_dump($e->getTrace()); } Generates.. array 0 => array 'file' => 'C:\Inetpub\Framework\www\bug.php' (length=32) 'line' => 17 'function' => 'errorToExceptionHandler' (length=23) 'args' => array 0 => 1024 1 => 0 1 => ....This definately seems to be a bug... <?php class AssertException extends ErrorException { function __construct($script, $line, $message) { parent::__construct('Assertion Exception', 0, E_USER_WARNING, $script, $line); } } function assertToExceptionHandler($script, $line, $message ) { throw new AssertException($script, $line, $message); } assert_options(ASSERT_ACTIVE, 1); assert_options(ASSERT_WARNING, 0); assert_options(ASSERT_QUIET_EVAL, 0); assert_options(ASSERT_CALLBACK, 'assertToExceptionHandler'); function test($a) { assert('$a > 0 && $a < 10'); } try { test(11); } catch (Exception $e) { echo '<pre>'; var_dump($e->getTrace()); echo '</pre>'; } ?> Outputs array(3) { [0]=> array(2) { ["function"]=> string(24) "assertToExceptionHandler" ["args"]=> array(1) { [0]=> string(17) "$a > 0 && $a < 10" } } [1]=> array(4) { ["file"]=> string(30) "C:\Inetpub\Framework\www\s.php" ["line"]=> int(24) ["function"]=> string(6) "assert" ["args"]=> array(1) { [0]=> int(11) } } [2]=> array(3) { ["file"]=> string(30) "C:\Inetpub\Framework\www\s.php" ["line"]=> int(29) ["function"]=> string(4) "test" } } Which seems off by one each line of the trace has the previous stack calls arguments.