php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9386 set_error_handler() doesn't always catch errors
Submitted: 2001-02-21 16:39 UTC Modified: 2001-06-17 04:56 UTC
From: stevem at mycomputer dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: Red Hat Linux 6.2
Private report: No CVE-ID: None
 [2001-02-21 16:39 UTC] stevem at mycomputer dot com
The files error_handler.inc, parse_error.php, and php_warning.php are included below.

We have error_handler.inc as the auto_prepend_file in php.ini.  It defines an error handling function and then sets it.  However, when a parse error occurs, our error handler is not called, as you can see in the following snippet of execution.  It is clear that the error handler is not being called in the second case.

*******************************************
[httpd@dev10 php]$ php -q php_warning.php 
ERROR HANDLER
[httpd@dev10 php]$ php -q parse_error.php 
<br>
<b>Fatal error</b>:  Call to undefined function:  thisisjunk() in <b>parse_error.php</b> on line <b>3</b><br>
[httpd@dev10 php]$
*******************************************



error_handler.inc
==================================
<?
 
/*
 
From php.ini:
 
 E_ALL             - All errors and warnings
 E_ERROR           - fatal run-time errors
 E_WARNING         - run-time warnings (non fatal errors)
 E_PARSE           - compile-time parse errors
 E_NOTICE          - run-time notices (these are warnings which often result from a bug in
                     your code, but it's possible that it was intentional (e.g., using an
                     uninitialized variable and relying on the fact it's automatically
                     initialized to an empty string)
 E_CORE_ERROR      - fatal errors that occur during PHP's initial startup
 E_CORE_WARNING    - warnings (non fatal errors) that occur during PHP's initial startup
 E_COMPILE_ERROR   - fatal compile-time errors
 E_COMPILE_WARNING - compile-time warnings (non fatal errors)
 
*/
 

function myc_log_error($timeday, $message, $server, $level, $service, $script_name, $context) {
        echo "ERROR HANDLER\n";
}
 
function myc_error_handler($errno, $errstr, $errfile, $errline, $context) {
        switch($errno) {
                case E_NOTICE:
                case E_USER_NOTICE:
                case 0: // this occurs when the statement was prepended with an @ symbol
                        // do nothing
                break;
 
                case E_WARNING:
                case E_CORE_WARNING:
                case E_COMPILE_WARNING:
                case E_USER_WARNING:
                        myc_log_error(date("Y-m-d H:i:s"), $errstr, $GLOBALS['HOSTNAME'], $errno, $GLOBALS['SERVER_NAME'], $errfile, $context);
                break;
 
                default:
                        myc_log_error(date("Y-m-d H:i:s"), $errstr, $GLOBALS['HOSTNAME'], $errno, $GLOBALS['SERVER_NAME'], $errfile, $context);
                        header("Location: http://www.mycomputer.com/errors/error_available.html");
                        echo "Hello!\n";
                        exit();
                break;
        }
}
 
set_error_handler("myc_error_handler");
 

?>
==================================

php_warning.php
==================================
<?
 
foreach($arr as $hello) {
        echo "$hello\n";
}
 
?>
===================================

parse_error.php 
===================================
<?
 
thisisjunk();
 
?>
===================================

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-17 04:56 UTC] jmoore@php.net
FATAL errors are not passed through user error handlers due to the fact the engine may be unstable and this could present security issues, instead the engine reports the error via its default mechanism as described in php.ini and then shutsdown as gracefully as possible.

- James
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 21:01:31 2024 UTC