1<?php 2 3namespace ComboStrap; 4 5class ErrorHandler 6{ 7 8 9 10 11 /** 12 * @return void 13 */ 14 public static function phpErrorAsException(): void 15 { 16 set_error_handler(function($errorNumber, $errorMessage, $errorFile, $errorLine) { 17 // error was suppressed with the @-operator 18 if (0 === error_reporting()) { 19 return false; 20 } 21 throw ( 22 (new ExceptionPhpError($errorMessage, 0, $errorNumber )) 23 ->setErrorFile($errorFile) 24 ->setErrorLine($errorLine) 25 ); 26 27 }); 28 } 29 30 31 static public function restore() 32 { 33 restore_error_handler(); 34 } 35} 36