php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #61796 trigger_error with custom line and file
Submitted: 2012-04-21 09:15 UTC Modified: 2021-03-31 17:29 UTC
Votes:2
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: andeol3 at cam dot upv dot es Assigned: cmb (profile)
Status: Wont fix Package: *General Issues
PHP Version: 5.4.0 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: andeol3 at cam dot upv dot es
New email:
PHP Version: OS:

 

 [2012-04-21 09:15 UTC] 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 );


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-16 15:37 UTC] notdefix at hotmail dot com
Of Interest: #38332
 [2021-03-31 17:29 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-03-31 17:29 UTC] cmb@php.net
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>
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun May 16 06:01:23 2021 UTC