PHP code example of kegi / php-error-handler
1. Go to this page and download the library: Download kegi/php-error-handler library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kegi / php-error-handler example snippets
namespace Your\Project\Bootstrap;
use KeGi\PhpErrorHandler\PhpErrorHandler;
use KeGi\PhpErrorHandler\PhpFatalErrorException;
class App
{
public function __construct() {
/*instanciate the error handler*/
(new PhpErrorHandler())
->setDebug(false) //prod
#->setErrorCallback([$this, 'handleError']) //most projects don't need this
->setFatalErrorCallback([$this, 'handleFatalError'])
->setUnrecoverableErrorCallback([$this, 'handleUnrecoverableError']);
}
public function run()
{
//run your application...
throw new \Exception('Uncaught exception');
//or...
trigger_error('Uncaught error', E_USER_ERROR);
}
public function handleFatalError(PhpFatalErrorException $phpFatalErrorException)
{
// you can check the php error like this :
if($phpFatalErrorException->getCode() === E_PARSE){
//parse error occured...
}
// you would normally call your router and emit a response
return 'A fatal occured occured...';
}
public function handleUnrecoverableError()
{
//you could
bash
composer