А можно ли вообще сделать выброс из register_shutdown_function?

Пытаюсь сделать выброс из register_shutdown_function — не работает.

То есть исключение внутри register_shutdown_function не перехватывается в set_exception_handler.

 

@don.bidon при чём тут ответ гадалки, меня интересует ответ уровня: если все функции отработали и последняя shutdown, то распространяется ли на неё действие функций, если она по ходу последняя, то есть всё что можно отработало и попадёт ли шатдаун в отлов выброса, если шатдаун последнее что может быть, видит ли её Throwable?

или мы в 2023 году так и будем ловить несуществующий трейт шатдаунами

 

еблысь

PHP:
  1. class Debugger
  2. {
  3.     private $container;
  4.  
  5.     public function __construct(Container $container)
  6.     {
  7.         $this->container = $container;
  8.     }
  9.  
  10.     public function __invoke(Request $request, Response $response)
  11.     {
  12.         set_error_handler(function ($code, $text, $file, $line) use ($request, $response) {
  13.             call_user_func(
  14.                 $this->container->get($this->container->get(‘debugger’)[‘handler’]),
  15.                 $request,
  16.                 $response,
  17.                 [
  18.                     ‘head’ => ‘error’,
  19.                     ‘code’ => $code === 404 ? 404 : 500,
  20.                     ‘text’ => $text,
  21.                     ‘file’ => $file,
  22.                     ‘line’ => $line
  23.                 ]
  24.             );
  25.         });
  26.  
  27.         set_exception_handler(function (Throwable $throwable) use ($request, $response) {
  28.             call_user_func(
  29.                 $this->container->get($this->container->get(‘debugger’)[‘handler’]),
  30.                 $request,
  31.                 $response,
  32.                 [
  33.                     ‘head’ => ‘exception’,
  34.                     ‘code’ => $throwable->getCode() === 404 ? 404 : 500,
  35.                     ‘text’ => $throwable->getMessage(),
  36.                     ‘file’ => $throwable->getFile(),
  37.                     ‘line’ => $throwable->getLine()
  38.                 ]
  39.             );
  40.         });
  41.  
  42.         register_shutdown_function(function () use ($request, $response) {
  43.  
  44.             if ($error = error_get_last()) {
  45.                 call_user_func(
  46.                     $this->container->get($this->container->get(‘debugger’)[‘handler’]),
  47.                     $request,
  48.                     $response,
  49.                     [
  50.                         ‘head’ => ‘shutdown’,
  51.                         ‘code’ => $error[‘type’] === 404 ? 404 : 500,
  52.                         ‘text’ => $error[‘message’],
  53.                         ‘file’ => $error[‘file’],
  54.                         ‘line’ => $error[‘line’]
  55.                     ]
  56.                 );
  57.             }
  58.         });
  59.     }
  60. }
 

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *