php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47887 Permit custom error types with trigger_error()
Submitted: 2009-04-03 14:29 UTC Modified: 2009-04-03 19:36 UTC
From: aragon at phat dot za dot net Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.9 OS: FreeBSD
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: aragon at phat dot za dot net
New email:
PHP Version: OS:

 

 [2009-04-03 14:29 UTC] aragon at phat dot za dot net
Description:
------------
It would be useful if trigger_error would accept custom error types.  Although I can do this with Exceptions, I can't see a way of sending variable context from where an exception is thrown to the exception handler, and loosing variable context would be a deal breaker.


Reproduce code:
---------------
define('E_CUSTOM_1', -1);
define('E_CUSTOM_2', -2);
function error_handler ($errno, $errmsg, $scriptname, $scriptline, $errcontext) {
   if ($errno == E_CUSTOM_1) die('custom error type');
}
set_error_handler('error_handler');
trigger_user('message', E_CUSTOM_1);


Expected result:
----------------
custom error type


Actual result:
--------------
PHP Warning:  Invalid error type specified in - on line 7


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-03 19:36 UTC] johannes@php.net
This isn't possible, as the whole error infrastructure, including all logging components and therelike have to know the error levels which might occur. You could use a global variable to transport your own error code for example.
 [2012-07-16 14:29 UTC] notdefix at hotmail dot com
It would be nice if a couple more error levels would be supported, for example

in addition to the supported:
  E_USER_ERROR
  E_USER_WARNING
  E_USER_NOTICE
  E_USER_DEPRECATED

please also add:
  E_USER_INFO ..: for example: 'system starting'
  E_USER_DEBUG .: for example: 'reading line 8 of config file'

This would bring it more in line with the error levels common in many systems.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 14:01:32 2024 UTC