note 129784 added to function.trigger-error
| From: | theking2@king.ma | Date: | Sun, 29 Sep 2024 11:04:04 +0000 |
| Subject: | note 129784 added to function.trigger-error | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221569@lists.php.net to get a copy of this message | ||
The function trigger_error will terminate the script if $error_level is equal or higher than
E_USER_ERROR.
If you write your own error handler you will have to do these yourself.
Example in which we assume the global LOG constant points to a PSR2 logging interface.
<?php
set_error_handler( function ($errno, $errstr, $errfile, $errline) {
// error was suppressed with the @-operator
if( 0 === error_reporting() ) {
return false;
}
switch($errno) {
default:
LOG->error( "Unknown error type: [$errno] $errstr", [ 'file' =>
$errfile, '@' => $errline ] );
exit(1);
case E_USER_ERROR: // fall through
case E_WARNING: // treat PHP warnings are errors
LOG->error( $errstr, [ 'file' => $errfile, '@' => $errline ] );
exit(1);
case E_USER_DEPRECATED:
case E_DEPRECATED:
LOG->error( "DEPRECATED $errstr", [ 'file' => $errfile, '@'
=> $errline ] );
break;
case E_USER_WARNING: // fall through
case E_NOTICE: // treat PHP notices are warnings
LOG->warning( $errstr, [ 'file' => $errfile, '@' => $errline ] );
break;
case E_USER_NOTICE:
LOG->notice( $errstr, [ 'file' => $errfile, '@' => $errline ] );
break;
case E_ERROR: // fall through
case E_RECOVERABLE_ERROR:
LOG->critical( $errstr, [ 'file' => $errfile, '@' => $errline ] );
exit(1);
}
/* Don't execute PHP internal error handler */
return true;
} );
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 83.97.87.43)
----
Manual Page -- https://php.net/manual/en/function.trigger-error.php
Edit -- https://main.php.net/note/edit/129784
Del: integrated -- https://main.php.net/note/delete/129784/integrated
Del: useless -- https://main.php.net/note/delete/129784/useless
Del: bad code -- https://main.php.net/note/delete/129784/bad+code
Del: spam -- https://main.php.net/note/delete/129784/spam
Del: non-english -- https://main.php.net/note/delete/129784/non-english
Del: in docs -- https://main.php.net/note/delete/129784/in+docs
Del: other reasons-- https://main.php.net/note/delete/129784
Reject -- https://main.php.net/note/reject/129784
Search -- https://main.php.net/manage/user-notes.php