What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.



error_reporting — Sets the level of error reporting for the current script.


int error_reporting([reporting_level]);
int reporting_level (optional): Level of error reporting to use


An integer (bitmask) containing the previous level of error reporting; FALSE on error


error_reporting() sets which level(s) of PHP errors are reported within the current document and returns the previous level of error reporting. The new settings take effect immediately after the function call is made.

If error_reporting() is called without any arguments, the current level of error reporting is returned.

The error reporting level can be set with either an integer or a named constant. Multiple integers or constants can be combined with bitwise operators. Any PHP bitwise operator can be used (&, |, ~, ^, << and >>).

Constant Name Description Value PHP Version
E_ERROR Fatal errors that occur at runtime. 1 3+, 4+
E_WARNING Non-fatal errors that occur at runtime. 2 3+, 4+
E_PARSE Parse errors (caused by invalid syntax). 4 3+, 4+
E_NOTICE Non-critical errors - can usually be suppressed/ignored. If this level of error reporting is set, errors generated by the use of undefined variables are displayed. Perl programmers accustomed to using the -w switch may find that they prefer having this level of error reporting active. 8 3+, 4+
E_CORE_ERROR Fatal errors that occur at PHP engine startup. 16 4+
E_CORE_WARNING Non-fatal errors that occur at PHP engine startup. 32 4+
E_COMPILE_ERROR Fatal errors that occur at script compile-time. 64 4+
E_COMPILE_WARNING Non-fatal errors that occur at script compile-time. 128 4+
E_USER_ERROR User-thrown fatal error, thrown using trigger_error() 256 4+
E_USER_WARNING User-thrown non-fatal error, thrown using trigger_error() 512 4+
E_USER_NOTICE User-thrown non-critical error, thrown using trigger_error() 1024 4+
E_ALL The combined value of all available error levels. Since this can be a different value in different PHP versions, it is a good idea to use the named constant and not the numeric value. varies by PHP version 3+, 4+


The use of named constants is strongly recommended. While the integer values that represent various error states may change as time passes, the named constants will be much more stable.


If you have defined a custom error handler using set_error_handler() , then the level of error reporting set using the error_reporting() function or configuration directive will only affect the E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, and E_COMPILE_WARNING error levels. All other error levels are expected to be handled by the custom error handler.


PHP Version: 3+, 4+


Example 270. Basic use of error_reporting()

// Enable every level of error reporting
error_reporting (E_ALL);

// Enable the E_ERROR, E_WARNING, and E_PARSE error reporting levels
error_reporting (E_ERROR | E_WARNING | E_PARSE);

// Disable all levels of error reporting.
// Usually this is a bad idea. To prevent errors from being displayed,
// disable the display_errors directive in the php.ini file or via ini_set
// i.e. ini_set ('display_errors', 0);
error_reporting (0);

// Remove E_NOTICE from the current level of error reporting.
// Use error_reporting to fetch the current level of error reporting.
error_reporting (error_reporting (0) & ~ E_NOTICE);

Example 271. Use error_reporting() to help debug code


// Make a handy class that simplifies calling the debugging code
// multiple times within the same script.

class debug {
    // Define variables that store the old error reporting and logging states
    var $old_error_level;
    var $old_display_level;
    var $old_error_logging;
    var $old_error_log;

    // For storing the path to the temporary log file
    var $debug_log;

    function debug ($log = 'debug.log') {
        $this->debug_log = $log;

    function start () {
        // Show all errors
        $this->old_error_level = error_reporting (E_ALL);

        // Make sure that the errors get displayed
        $this->old_display_level = ini_set ('display_errors', 1);
        // Make sure that error logging is enabled
        $this->old_error_logging = ini_set ('log_errors', 1);

        // Make sure that the errors get logged to a special log file
        $this->old_log_setting = ini_set ('error_log', $this->debug_log);

    function stop () {
        // Use the stored error and display settings to 
        // restore the previous state
        error_reporting ($this->old_error_level);
        ini_set ('display_errors', $this->old_display_level);
        ini_set ('log_errors', $this->old_error_logging);
        ini_set ('error_log', $this->debug_log);

// Instantiate the class so that we can use it
$debug = new debug ();

// Start debugging
$debug->start ();

// Code to debug
// The line below should generate an undefined variable warning
print $foo . 'Hello ';

// Stop debugging and restore previous error handling and logging values
$debug->stop ();

// Even though $bar is undefined, unless you have E_NOTICE enabled, no error will be generated
print $bar . 'World';

PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at The authors of this book have elected not to choose any options under the OPL. This online book was obtained from and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.