Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

error_reporting

(PHP 3, PHP 4, PHP 5)

error_reporting -- Sets which PHP errors are reported

Описание

int error_reporting ( [int level] )

The error_reporting() function sets the error_reporting directive at runtime. PHP has many levels of errors, using this function sets that level for the duration (runtime) of your script.

Список параметров

level

The new error_reporting level. It takes on either a bitmask, or named constants. Using named constants is strongly encouraged to ensure compatibility for future versions. As error levels are added, the range of integers increases, so older integer-based error levels will not always behave as expected.

The available error level constants are listed below. The actual meanings of these error levels are described in the predefined constants.

Таблица 1. error_reporting() level constants and bit values

valueconstant
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
2047 E_ALL
2048 E_STRICT
4096 E_RECOVERABLE_ERROR

Возвращаемые значения

Returns the old error_reporting level.

Примеры

Пример 1. error_reporting() examples

<?php

// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting(E_ALL);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

?>

Примечания

Внимание

With PHP > 5.0.0 E_STRICT with value 2048 is available. E_ALL does NOT include error level E_STRICT (but in PHP 6 it does though). Most of E_STRICT errors are evaluated at the compile time thus such errors are not reported in the file where error_reporting is enhanced to include E_STRICT errors.

Смотрите также

The display_errors directive
ini_set()



restore_error_handler> <error_log
Last updated: Sat, 27 Jan 2007
 
add a note add a note User Contributed Notes
error_reporting
bbaez at biospectra dot com
09-May-2007 05:02
frederick noted this in 2005 but want to stress the point here

If you set error_reporting in httpd.conf or within a script (some PHP versions) then you must use the integer value and not the string:

Example httpd.conf:
E_ALL ^ E_NOTICE would be:
php_value error_reporting 6135

otherwise the error will not display during output.
antickon AT gmail.com
04-Apr-2007 05:21
regarding what vdephily at bluemetrix dot com said ( see http://be.php.net/manual/en/function.error-reporting.php#50228 )

<?php
echo $foobar->field;
?>

also initializes $foobar (as an instance of stdClass), so this code will not cause any notices.
bitagenda at gmail dot com
08-Mar-2007 08:36
A simple and effective way to catch Fatal errors.
From here you can go forward with your own ideas and elaborate a detailed error report.

The principle is simple and ready to test on your system

Fatal errors are not currently catched and you should have display errors off in production sites, but may be you need to test the system so you want a fast an easy way to see fatal errors in your currently running site, without the users seeing those Fatal errors as recomended.

You must have this function

function catchFatalErrors($p_OnOff='On'){
    ini_set('display_errors','On');
    $phperror='><div id="phperror" style="display:none">';
    ini_set('error_prepend_string',$phperror);
    $phperror='</div>><form name="catcher" action="/sos.php" method="post" ><input type="hidden" name="fatal"  value=""></form> <script> document.catcher.fatal.value = document.getElementById("phperror").innerHTML; document.catcher.submit();</script>';
    ini_set('error_append_string',$phperror);
}

Now activate your fatal error catcher

catchFatalErrors();

Just to test write this inexistent function

Bitagenda();

That's all. As you can see there will be a form posted with action="/sos.php", of course you can name this page at your liking, in this case is at the site's root.

Have ready your page sos.php, and elaborate on that. Of course change the mail address to yours,and display a message to the user at your liking.

<?php
if (isset($_POST['fatal'])){
 
error_log($_POST['fatal'],1,'bitagenda@gmail.com');
}
?>

 "System Out of Service. Thanks for waiting."

The other fact about this handler is that even if you do not redirect the Fatal Error, prepending
><div style="display:none">
and appending
</div>

Then writting yor personal message

" Sorry, fatal bug."

Will hide the fatal error message from the user, but will be visible in the browsers soure code view.

What happens if you redirect the page before displaying the error? I don
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com
Z058440144362 Z348613067571