php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37224 ErrorException::getTrace() includes the function name of the error_handler
Submitted: 2006-04-27 15:18 UTC Modified: 2006-06-05 15:52 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: Jared dot Williams1 at ntlworld dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.3 OS: Win2000
Private report: No CVE-ID: None
 [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)



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-27 18:24 UTC] Jared dot Williams1 at ntlworld dot com
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 => 
....
 [2006-05-01 15:04 UTC] tony2001@php.net
Expected behaviour.
No bug here.
 [2006-05-01 15:31 UTC] Jared dot Williams1 at ntlworld dot com
How can the trace containing the function name of one function, and the arguments to another be expected?
 [2006-05-04 17:31 UTC] Jared dot Williams1 at ntlworld dot com
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.
 [2006-06-05 15:52 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The trace only "skips" the error handler function, nothing 
else is "skipped".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 23:01:29 2024 UTC