ID: 37224
User updated by: Jared dot Williams1 at ntlworld dot com
Reported By: Jared dot Williams1 at ntlworld dot com
-Status: Bogus
+Status: Open
Bug Type: Scripting Engine problem
Operating System: Win2000
-PHP Version: 5.1.3RC2
+PHP Version: 5.1.3
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2006-05-01 15:31:20] 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-01 15:04:30] [EMAIL PROTECTED]
Expected behaviour.
No bug here.
------------------------------------------------------------------------
[2006-04-27 18:24:03] 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-04-27 15:18:17] 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)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=37224&edit=1