Req #61796 [Opn->Wfx]: trigger_error with custom line and file

From: Date: Wed, 31 Mar 2021 17:29:38 +0000
Subject: Req #61796 [Opn->Wfx]: trigger_error with custom line and file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233106@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61796&edit=1

 ID:                 61796
 Updated by:         cmb@php.net
 Reported by:        andeol3 at cam dot upv dot es
 Summary:            trigger_error with custom line and file
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            *General Issues
 PHP Version:        5.4.0
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Apparently, there is not much interest in this, and in my opinion,
extending the traditionally error mechanism isn't the way to go
anyway.  If you still feel that this is a worthwhile improvement,
please pursue the RFC process[1].

[1] <https://wiki.php.net/rfc/howto>


Previous Comments:
------------------------------------------------------------------------
[2012-07-16 15:37:58] notdefix at hotmail dot com

Of Interest: #38332

------------------------------------------------------------------------
[2012-04-21 09:15:24] andeol3 at cam dot upv dot es

Description:
------------
Wouldn't it be nice if the trigger_error function could be called with a user-defined $errline
and $errfile? Imagine you were writing an Abstract Class and wanted to handle class errors
internally. Theoretically, you could retrieve the name of the current error handler by using the
set_error_handler function and then the restore_error_handler function. Then, you could use
call_user_func to trigger a user-defined error. However, if no error handler has been defined
previously, set_error_handler will return null and the procedure would fail alltogether. On the
other hand, calling trigger_error will show the file and line where the trigger_error function was
called (which is very unuseful).

Test script:
---------------
// Get the current error handler
function void ( $errno, $errstr ) { }
$error_handler = set_error_handler ( "void" );
restore_error_handler();

// User-define error
$error_arguments = array ( $errno, $errstr, $errfile, $errline );

// Trigger error
call_user_func ( $error_handler, $error_arguments ); // This will only work as long as an error
handler has been previously set.

// Instead, the following function is proposed:
trigger_error ( string $error_msg, int $error_type = E_USER_NOTICE, string $error_file, string
$error_line );



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



--
Edit this bug report at https://bugs.php.net/bug.php?id=61796&edit=1


Thread (3 messages)

« previous php.bugs (#233106) next »