1

我正在使用以下脚本处理错误:

<?php # config.inc.php

// This script establishes email default settings.
// This script determines how errors are handled.

// Email Settings
$site['from_name'] = 'x'; // from email name
$site['from_email'] = 'x@x.com'; // from email address

// Just in case we need to relay to a different server, 
// provide an option to use external mail server.
$site['smtp_mode'] = 'enabled'; // enabled or disabled
$site['smtp_host'] = 'mail.x.com';
$site['smtp_port'] = null;
$site['smtp_username'] = 'admin@x.com'; 
$site['smtp_password'] = 'x';

// Error handling:
// Flag variable for site status:
$live = TRUE;

ini_set('display_errors','On');
error_reporting(E_ALL);

// Error log email address:
$admin_email = 'x@x.com';

date_default_timezone_set('America/New_York');

// Create the error handler.
function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {

    global $live, $admin_email;

    // Build the error message.
    $message = "An error occurred in script '$e_file' on line $e_line: \n<br />$e_message\n<br />";

    // Add the date and time.
    $message .= "Date/Time: " . date('n-j-Y H:i:s') . "\n<br />";

    // Append $e_vars to the $message.
    $message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n<br />";

    if ($live) { // Don't show the specific error.

        error_log ($message, 1, $admin_email); // Send email.

        // Only print an error message if the error isn't a notice.
        if ($e_number != E_NOTICE) {
            echo '<div id="Error">A system error occurred. An administrator has been notified. We apologize for the inconvenience.</div><br />';
        }

    } else { // Development (print the error).
        echo '<div id="Error">' . $message . '</div><br />';
    }

} // End of my_error_handler() definition.

// Use my error handler.
set_error_handler ('my_error_handler');

?>

如果我将此脚本包含在有错误的脚本中,则不会显示该错误。如果我注释掉对 set_error_handler() 的调用,则会显示错误。我做错了什么可能导致这种行为?

4

1 回答 1

1

从文档http://php.net/manual/en/function.set-error-handler.php

重要的是要记住,对于由 error_types 指定的错误类型,标准的 PHP 错误处理程序完全被绕过,除非回调函数返回 FALSE。

让你的处理程序返回FALSE

于 2012-05-18T20:20:28.153 回答