ID:               38332
 User updated by:  RQuadling at GMail dot com
 Reported By:      RQuadling at GMail dot com
-Status:           Bogus
+Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: Windows XP SP2
 PHP Version:      5.2.0RC1
 New Comment:

No.

I DON'T want an array as the first parameter. Type hinting works for
arrays and classes, but not other types.

The error is when an array is supplied and __NOT__ wanted!!!!

I know this is an obtuse issue, the real issue is I want to generate a
user error but have the calling line id'd as the fault, not the
trigger_error() line as there is nothing wrong there.


Previous Comments:
------------------------------------------------------------------------

[2006-08-04 15:17:54] [EMAIL PROTECTED]

Changind 
function first_param_not_array($data)
to
function first_param_not_array(array $data)
does it for you automatically.

------------------------------------------------------------------------

[2006-08-04 15:06:34] RQuadling at GMail dot com

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 this bug report at http://bugs.php.net/?id=38332&edit=1

Reply via email to