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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 09:01:33 2025 UTC