PHP.mk документација

restore_error_handler

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.restore-error-handler.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.restore-error-handler.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
restore_error_handler

Референца за `function.restore-error-handler.php` со подобрена типографија и навигација.

function.restore-error-handler.php

restore_error_handler

(PHP 4 >= 4.0.1, PHP 5, PHP 7, PHP 8)

restore_error_handler(PHP 4 >= 4.0.1, PHP 5, PHP 7, PHP 8)

= NULL

restore_error_handler(): true

Ја враќа претходната функција за ракување со грешки set_error_handler()Се користи по промена на функцијата за ракување со грешки користејќи

Параметри

Оваа функција нема параметри.

Вратени вредности

Секогаш враќа true.

Примери

Пример #1 restore_error_handler() example

, за да се вратите на претходната функција за ракување со грешки (што може да биде вградена или кориснички дефинирана функција). unserialize() Одлучи дали

<?php
function unserialize_handler($errno, $errstr)
{
echo
"Invalid serialized value.\n";
}

$serialized = 'foo';
set_error_handler('unserialize_handler');
$original = unserialize($serialized);
restore_error_handler();
?>

Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред

Invalid serialized value.

Види Исто така

  • error_reporting() - Поставува кои PHP грешки се пријавуваат
  • set_error_handler() - Поставува кориснички дефинирана функција за ракување со грешки
  • get_error_handler() Примерот подолу покажува како се справува со внатрешни исклучоци со активирање грешки и нивно справување со корисничка дефинирана функција:
  • restore_exception_handler() - Враќа претходно дефинирана функција за ракување со исклучоци
  • trigger_error() - Генерира порака за грешка/предупредување/известување на корисничко ниво

Белешки од корисници 4 белешки

edgarinvillegas на hotmail точка com
пред 17 години
Isolde is kind of wrong. The error handlers are stacked with set_error_handler(), and popped with restore_error_handler(). Here i put an example:

<?php
    mysql_connect("inexistent"); //Generate an error. The actual error handler is set by default

    function foo1() {echo "<br>Error foo1<br>";}
    function foo2() {echo "<br>Error foo2<br>";}
    function foo3() {echo "<br>Error foo3<br>";}
    
    set_error_handler("foo1");    //current error handler: foo1
    set_error_handler("foo2");    //current error handler: foo2
    set_error_handler("foo3");    //current error handler: foo3
    
    mysql_connect("inexistent");    
    restore_error_handler();        //now, current error handler: foo2
    mysql_connect("inexistent");     
    restore_error_handler();        //now, current error handler: foo1
    mysql_connect("inexistent"); 
    restore_error_handler();        //now current error handler: default handler
    mysql_connect("inexistent");
    restore_error_handler();        //now current error handler: default handler (The stack can't pop more)
?>
предизвика грешка, а потоа вратете ја оригиналната функција за ракување со грешки.
пред 22 години
As the docs say, restore_error_handler() revert to the *previous error handler*... even if it is the same. A bug made me set twice my custom error handler and later when I was calling restore_error_handler() to restore the built-in handler nothing seemed to happen... this puzzled me for a while!
lsole at maresme dot net
пред 8 години
Calling restore_error_handler from within an error handler might result in unexpected behaviour:

<?php
error_reporting(0);

set_error_handler('handleError1');
trigger_error('1-stack:h1');

set_error_handler('handleError2');
trigger_error('2-stack:h1,h2');

trigger_error('6-stack:h1,h2');
trigger_error('7-stack:h1,h2');

function handleError1($code, $message, $file = '', $line = 0, $context = array())
{
    echo  __METHOD__ . ' ' . $message . PHP_EOL;
}

function handleError2($code, $message, $file = '', $line = 0, $context = array())
{
    trigger_error('3-DEFAULT'); // This will use the php's default error handler

    echo  __METHOD__ . ' ' . $message . PHP_EOL;

    set_error_handler('handleError3');
    trigger_error('4-stack:h1,h2,h3');

    restore_error_handler(); // This will restore the handleError1 instead of the default error handler
    trigger_error('5-DEFAULT');
}

function handleError3($code, $message, $file = '', $line = 0, $context = array())
{
    echo  __METHOD__ . ' ' . $message . PHP_EOL;
}

?>

The above code will output:

handleError1 1-stack:h1
handleError2 2-stack:h1,h2
handleError3 4-stack:h1,h2,h3
handleError1 5-DEFAULT
handleError1 6-stack:h1,h2
handleError1 7-stack:h1,h2

The following workaround can be used:

<?php

error_reporting(0);

set_error_handler('handleError1');
trigger_error('1-stack:h1');

set_error_handler('handleError2');
trigger_error('2-stack:h1,h2');

trigger_error('6-stack:h1,h2');
trigger_error('7-stack:h1,h2');

function handleError1($code, $message, $file = '', $line = 0, $context = array())
{
    echo __METHOD__ . ' ' . $message . PHP_EOL;
}

function handleError2($code, $message, $file = '', $line = 0, $context = [])
{
    restore_error_handler(); // This will restore the previous error handler
    set_error_handler('count', 0); // Set a dummy method for error handling, it will never be called because $error_type = 0
    try
    {
        trigger_error('3-DEFAULT');

        echo __METHOD__ . ' ' . $message . PHP_EOL;

        set_error_handler('handleError3');
        trigger_error('4-stack:h1,h2,h3');

        restore_error_handler();
        trigger_error('5-DEFAULT');
    }
    finally
    {
        restore_error_handler(); // Restore the previous error handler
        set_error_handler('handleError2'); // Set the current error handler again
    }
}

function handleError3($code, $message, $file = '', $line = 0, $context = [])
{
    echo __METHOD__ . ' ' . $message . PHP_EOL;
}
?>

which will output:

handleError1 1-stack:h1
handleError2 2-stack:h1,h2
handleError3 4-stack:h1,h2,h3
handleError2 6-stack:h1,h2
handleError3 4-stack:h1,h2,h3
handleError2 7-stack:h1,h2
handleError3 4-stack:h1,h2,h3
TiMESPLiNTER
пред 10 години
Works also for restoring nested error handlers:

<?php

error_reporting(E_ALL);

echo '<pre>';

set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {
    echo 'ErrorHandler 1: ' , $errstr , PHP_EOL;
});

trigger_error('Error 1');

set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {
    echo 'ErrorHandler 2: ' , $errstr , PHP_EOL;
});

trigger_error('Error 2');

restore_error_handler();

trigger_error('Error 3');

restore_error_handler();

trigger_error('Error 4');

?>
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.