Funkcija restore_exception_handler

Funkcija restore_exception_handler atjauno iepriekšējo izņēmumu apstrādes funkciju, kas bija aizstāta, izmantojot set_exception_handler. Šī funkcija nepieņem parametrus un neatgriež vērtības.

Sintakse

phprestore_exception_handler();

Piemērs

Uzstādīsim pielāgotu izņēmumu apstrādes funkciju un pēc tam atjaunosim iepriekšējo:

php<?php
  function customExceptionHandler($exception) {
    echo 'Pielāgots apstrādātājs: ' . $exception->getMessage();
  }
  
  set_exception_handler('customExceptionHandler');
  restore_exception_handler();
?>

Piemērs

Pārbaudīsim, ka pēc apstrādes funkcijas atjaunošanas darbojas standarta mehānisms:

php<?php
  set_exception_handler(function($exception) {
    echo 'Apstrādātājs 1: ' . $exception->getMessage();
  });
  
  set_exception_handler(function($exception) {
    echo 'Apstrādātājs 2: ' . $exception->getMessage();
  });
  
  restore_exception_handler();
  throw new Exception('Testa kļūda');
?>

Koda izpildes rezultāts:

php'Apstrādātājs 1: Testa kļūda'