From:             RQuadling at GMail dot com
Operating system: Windows XP SP2
PHP version:      5.2.0RC1
PHP Bug Type:     Feature/Change Request
Bug description:  trigger_error doesn't show where the error occurred.

Description:
------------
Using trigger_error/user_error only reports where the error was raised.

This is OK in most instances, but if the code is triggering an error due
to a problem with a functions parameters, it would be useful to know where
the call was made from.

So, using the debug_backtrace() function, the first element in the array
can be used to find the file and line number of the original call.

But, if you combine that with trigger_error/user_error, you also get the
file and line of the trigger statement.

The following code is an example showing a standard PHP produced error for
an incorrect parameter and a user generated error along similar lines.

As you can see from the output, the second message is wrapped with the
error for the trigger.

Ideally, a parameter to NOT show the additional data, but just use the
error message EXACTLY as generated would be great. Or to be able to
indicate that the file and line number to use is x levels in the backtrace
(0 would be the default indicating the current file and line, 1 would be
the caller if it is a function or a method, 2+ would be further down the
trace and probably not much use).

I've looked at zend_builtin_functions.c (/* $Id:
zend_builtin_functions.c,v 1.322 2006/07/27 08:20:52 dmitry Exp $ */ Lines
1207 - 1244) and zend_error (zend.c /* $Id: zend.c,v 1.368 2006/07/24
17:51:40 helly Exp $ */ Lines 1367+).

To no avail (I'm still too newbie to do to much source moding).

The example is all in 1 file, but if the function was in a library file
somewhere, and was 1 class per file, finding the error COULD take WAY too
long.

Reproduce code:
---------------
<?php
// Demonstrate a normal error.
$dummy = '';
echo sort($dummy);

function first_param_not_array($data)
        {
        if (is_array($data))
                {
                $a_Debug = debug_backtrace();
                trigger_error("first_param_not_array() expects parameter 1 to 
not be an
array, array given in {$a_Debug[0]['file']} on line
{$a_Debug[0]['line']}", E_USER_WARNING);
                }
        }

// Demonstrate the user error issue.
first_param_not_array($_ENV);
?>

Expected result:
----------------
Warning: sort() expects parameter 1 to be array, string given in
C:\user_gen_error.php on line 4

Warning: first_param_not_array() expects parameter 1 to not be an array,
array given in C:\user_gen_error.php on line 16

Actual result:
--------------
Warning: sort() expects parameter 1 to be array, string given in
C:\user_gen_error.php on line 4

Warning: first_param_not_array() expects parameter 1 to not be an array,
array given in C:\user_gen_error.php on line 16 in C:\user_gen_error.php
on line 11

-- 
Edit bug report at http://bugs.php.net/?id=38332&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=38332&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=38332&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=38332&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=38332&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=38332&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=38332&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=38332&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=38332&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=38332&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=38332&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=38332&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=38332&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=38332&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=38332&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=38332&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=38332&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=38332&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=38332&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=38332&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=38332&r=mysqlcfg

Reply via email to