ID: 24214
User updated by: gk at proliberty dot com
Reported By: gk at proliberty dot com
Status: Open
Bug Type: Feature/Change Request
Operating System: linux ; kernel 2.4.18
PHP Version: 4.3.2
New Comment:
I just realized that the expected result I entered is not consistent
with how debug_backtrace() works: function debug_backtrace must also be
listed. Here's a revision.
Expected result:
----------------
[EMAIL PROTECTED] xobj]$ php /tmp/a.php
Array(
[0] => Array
(
[file] => /tmp/a.php
[line] => 1
[function] => debug_backtrace
[args] => Array
(
)
)
)
Previous Comments:
------------------------------------------------------------------------
[2003-06-18 15:17:42] [EMAIL PROTECTED]
fwiw, I also feel this is a valid (and worthy) feature request and
assumed debug_backtrace() behaved as such.
------------------------------------------------------------------------
[2003-06-18 15:12:23] gk at proliberty dot com
Your solution is not elegant: adding extra parameters when
debug_backtrace() would be enough if it behaved consistently in all
cases.
This is also a documentation bug. Please do not set to 'bogus'. How can
a feature request be 'bogus'?
------------------------------------------------------------------------
[2003-06-18 14:38:01] [EMAIL PROTECTED]
Just pass the __FILE__ and __LINE__ to your phpc_trigger_error()
function, problem solved.
e.g.
phpc_trigger_error( $errorMessage,$errorCode,__FILE__, __LINE__,
debug_backtrace() );
------------------------------------------------------------------------
[2003-06-17 14:32:55] gk at proliberty dot com
I forgot to point out why the phpc_trigger_error() example is not an
adequate workaround for the lack of consistency in debug_backtrace().
Although I use __LINE__ and __FILE__ when $debug_backtrace[0] is not
set, these values are pretty useless since they are set from the
context of the phpc_trigger_error function, NOT from the place where it
was called from; where the error occured. If debug_backtrace() always
returned __LINE__ and __FILE__ we would have everything we need.
------------------------------------------------------------------------
[2003-06-17 13:30:07] gk at proliberty dot com
Yes, below is an example of how I'm using it.
The purpose is to work around the limited arguments passed to custom
error handlers, installed with set_error_handler(), which do not
receive class and function information.
The following function replaces trigger_error() by talking directly to
my custom error handler ('phpc_error_handler', omitted for brevity
below), using debug_backtrace() to pass class and function info for
prepending to error messages.
<?php
///////////////////////////////////////////////////////
/*
phpc_trigger_error( $errorMessage,$errorCode,$debugBacktrace=NULL )
same as PHP built-in trigger_error, with optional parameter
generate error message including debugging information
USAGE:
phpc_trigger_error( $errorMessage,$errorCode,debug_backtrace() );
*/
/////////////////////////////////////////////////////////
function phpc_trigger_error(
$errorMessage,$errorCode,$debug_backtrace=NULL ){
$errfile=__FILE__;
$errline=__LINE__;
$errclass="";
$errfunction="";
if (isset($debug_backtrace[0])){
$errfile=$debug_backtrace[0]['file'];
$errline=$debug_backtrace[0]['line'];
$errclass=$debug_backtrace[0]['class'];
$errfunction=$debug_backtrace[0]['function'];
}
if (!empty($errclass)) $errclass.='::';
if (!empty($errfunction)) $errfunction.='(): ';
$errorMessage=$errclass.$errfunction.$errorMessage.' ';
phpc_error_handler ($errorCode,$errorMessage,$errfile,$errline);
} // phpc_trigger_error()
?>
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/24214
--
Edit this bug report at http://bugs.php.net/?id=24214&edit=1