June 2017
Intermediate to advanced
536 pages
9h 49m
English
The PHP trigger_error() function provides a way to trigger a user-level error/warning/notice message. It can be used in conjunction with the built-in error handler, or with a user-defined error handler, as we saw in the previous section.
The trigger_error() function accepts two parameters, as per the following description:
bool trigger_error ( string $error_msg [, int $error_type = E_USER_NOTICE ] )
The $error_msg parameter has a limitation of 1024 bytes, whereas $error_type is limited to the E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, and E_USER_DEPRECATED constants.
Let's take a look at the following example:
<?php set_error_handler(function ($errno, $errstr) { echo 'Handler: ' . $errstr; }); echo 'start'; trigger_error('E_USER_ERROR!', ...