Development Wiki

Function.trigger error

From phpBB Development Wiki

Revision as of 17:31, 1 November 2008 by Chiron (Talk | contribs)

trigger_error –– Generates a user-level error/warning/notice message or page.


bool trigger_error ( string $error_msg [, int $error_type ] )

Used to trigger a user error condition and exiting the script. This function is useful when you need to generate a particular response to an exception at runtime. trigger_error() utilises the template: message_body.html in phpBB3.


The designated error message for this error. You can specify this message as simply the language key of a language variable, or a combination of text or language variables.

The designated error type for this error. It only works with the E_USER family of constants, and will default to E_USER_NOTICE. There are three error types that can be used: E_USER_NOTICE, E_USER_WARNING, and E_USER_ERROR.

E_USER_NOTICE (the default setting) is an "information" page. It's used for situations such as the message you receive upon completion of a post or logging in to phpBB3. In the ACP, E_USER_NOTICE displays a green information box.
E_USER_WARNING is used for warnings. On user-facing pages in the default phpBB3 styles, there is no visible difference between E_USER_NOTICE and E_USER_WARNING. In the ACP, E_USER_WARNING displays as a red “Error” box.
E_USER_ERROR should only be used for very severe errors, for example if sessions are unavailable. E_USER_ERROR is used for SQL Errors as an example. E_USER_ERROR displays a hard-coded error page for both user facing pages and within the ACP.


Example #1: Single language key example

if (!$result)

Example #2: Combined message and specified error type

$switch ($mode)
// [..]
trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_ERROR);

See Also