user_error
Description
The user_error of Error Handling for PHP generates a user-level error/warning/notice message.
Syntax
user_error ( string $error_msg [, int $error_type = E_USER_NOTICE ] ) : bool
Parameters
error_msg
The designated error message for this error. It's limited to 1024 bytes in length. Any additional characters beyond 1024 bytes will be truncated.
error_type
The designated error type for this error. It only works with the E_USER family of constants, and will default to E_USER_NOTICE.
Return
This function returns FALSE if wrong error_type is specified, TRUE otherwise.
Examples
1 · error_msg
<? function myfunction($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_USER_NOTICE: echo "NOTICE[$errno] $errstr\n"; exit(1); break; } return true; } function divide($numerator, $denominator) { if ($denominator == 1) { $error_msg = "unnecessary to divide by one"; user_error($error_msg); } return $numerator / $denominator; } set_error_handler("myfunction"); echo divide(10, 1); ?>
NOTICE[1024] unnecessary to divide by one
2 · error_type
<? function myfunction($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_USER_ERROR: echo "ERROR[$errno] $errstr\n"; exit(1); break; } return true; } function divide($numerator, $denominator) { if ($denominator == 0) { $error_msg = "cannot divide by zero"; $error_type = E_USER_ERROR; user_error($error_msg, $error_type); } return $numerator / $denominator; } set_error_handler("myfunction"); echo divide(10, 0); ?>
ERROR[256] cannot divide by zero