set_error_handler

Hi, how can I add some code to set_error_handler of PHPMaker?I would like to echo errors for example besides the normal PHP logs by function myErrorHandler.I have added the following code to Page_Head but got the error

function myErrorHandler($errno, $errstr, $errfile, $errline) { /////////////////////////////////////// line 184
    echo "<b>Custom error:</b> [$errno] $errstr<br>";
    echo " Error on line $errline in $errfile<br>";
}
set_error_handler("myErrorHandler");

error:

Fatal error: Cannot redeclare PHPMaker2023\spgmanagement\myErrorHandler() (previously declared in D:\admin\views\layout.php:184) in D:\admin\views\layout.php on line 184

mishanian wrote:

I have added the following code to Page_Head but got the error >


  1. You should not put it under Page_Head,
  2. You should not set_error_handler() (which will replace the original error handler),
  3. The built-in HttpErrorHandler handler already log the stack trace.

Hi,
Thanks for your reply,
I would like to add the following line whenever any errors happened. (assume $error is the exception error)

\Sentry\captureException($error);

unfortunately, I could not find any manual for using HttpErrorHandler,
I appreciate any advice.

As arbei mentioned above, you should not create your own error handler since it will replace the original error handler.

You should optimize the built-in error handler from the Slim framework that used by PHPMaker. You may see and learn the generated code from src/HttpErrorHandler.php file.