(PHP 4, PHP 5)

error_reporting Задает, какие ошибки PHP попадут в отчет


int error_reporting ([ int $level ] )

Функция error_reporting() задает значение директивы error_reporting во время выполнения. В PHP есть много уровней ошибок. Используя эту функцию, можно задать уровень ошибок времени выполнения скрипта, которые попадут в отчет. Если необязательный аргумент level не задан, error_reporting() вернет текущее значение уровня протоколирования ошибок.

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


Новое значение уровня error_reporting. Это может быть битовая маска или именованные константы. При использовании именованных констант нужно будет следить за совместимостью с новыми версиями PHP. В новых версиях могут добавиться новые уровни ошибок, увеличиться диапазон целочисленных типов. Все это может привести к нестабильной работе при использовании старых целочисленных обозначений уровней ошибок.

Доступные константы уровней ошибок и их описания приведены в разделе Предопределенные константы.

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

Возвращает старое значение уровня error_reporting либо текущее значение, если аргумент level не задан.

Список изменений

Версия Описание
5.4.0 E_STRICT стал частью E_ALL.
5.2.0 Добавлена E_RECOVERABLE_ERROR.
5.0.0 Добавлена E_STRICT (не входит в состав E_ALL).


Пример #1 Примеры использования error_reporting()


// Выключение протоколирования ошибок

// Включать в отчет простые описания ошибок
error_reporting(E_ERROR E_WARNING E_PARSE);

// Включать в отчет E_NOTICE сообщения (добавятся сообщения о 
//непроинициализированных переменных или ошибках в именах переменных)

// Добавлять сообщения обо всех ошибках, кроме E_NOTICE
// Это значение включено по умолчанию в php.ini
error_reporting(E_ALL E_NOTICE);

// Добавлять в отчет все PHP ошибки (см. список изменений)

// Добавлять в отчет все PHP ошибки

// То же, что и error_reporting(E_ALL);




Большинство E_STRICT ошибок отлавливаются на этапе компиляции, поэтому такие ошибки не включаются в отчет в файлах, где error_reporting расширен для включения E_STRICT ошибок (и наоборот).


Если передать -1, будут отображаться все возможные ошибки, даже если в новых версиях PHP добавятся уровни или константы. В версии PHP 5.4. передача константы E_ALL дает тот же результат.

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


error_reporting() has no effect if you have defined your own error handler with set_error_handler()

[Editor's Note: This is not quite accurate.

E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR and E_COMPILE_WARNING error levels will be handled as per the error_reporting settings.

All other levels of errors will be passed to the custom error handler defined by set_error_handler().

Zeev Suraski suggests that a simple way to use the defined levels of error reporting with your custom error handlers is to add the following line to the top of your error handling function:

if (!($type & error_reporting())) return;]
2000-10-03 02:37:18
To be enable to switch between error_reporting during development and release phases, one can define say 'php_error_reporting' in the main configuration file (ini like file: no PHP) for the application as:

# config.ini
# PHP error reporting. supported values are given below.
# 0 - Turn off all error reporting
# 1 - Running errors
# 2 - Running errors + notices
# 3 - All errors except notices and warnings
# 4 - All errors except notices
# 5 - All errors


# config.ini ends

Setting error_reporting in PHP files would be something like the code below, assuming the function getinivar() returns the variable value from the configuration file.

// setting PHP error reporting
switch(getinivar('php_error_reporting')) {
0error_reporting(0); break;
1error_reporting(E_ERROR E_WARNING E_PARSE); break;
2error_reporting(E_ERROR E_WARNING E_PARSE E_NOTICE); break;
3error_reporting(E_ALL ^ (E_NOTICE E_WARNING)); break;
4error_reporting(E_ALL E_NOTICE); break;
5error_reporting(E_ALL); break;

Feroz Zahid.
2004-09-08 07:31:00
The error_reporting() function won't be effective if your display_errors directive in php.ini is set to "Off", regardless of level reporting you set. I had to set

display_errors = On
error_reporting = ~E_ALL

to keep no error reporting as default, but be able to change error reporting level in my scripts.
I'm using PHP 4.3.9 and Apache 2.0.
2004-12-13 15:23:02
Note that E_NOTICE will warn you about uninitialized variables, but assigning a key/value pair counts as initialization, and will not trigger any error :

$foo $bar//notice : $bar uninitialized

$bar['foo'] = 'hello'// no notice, although $bar itself has never been initialized (with "$bar = array()" for example)

$bar = array('foobar' => 'barfoo');
$foo $bar['foobar'// ok

$foo $bar['nope'// notice : no such index
2005-02-22 05:40:47
If you get a weird mysql warnings like "Warning: mysql_query() []: Your query requires a full tablescan...", don't look for error_reporting settings - it's set in php.ini.
You can turn it off with
in your script

And, as of my opinion, it should be NOTICE, not WARNING level.
2005-02-22 11:03:13
Remember that the error_reporting value is an integer, not a string ie "E_ALL & ~E_NOTICE". 

This is very useful to remember when setting error_reporting levels in httpd.conf:

Use the table above or: 


To get the appropriate integer for your error-level. Then use:

php_admin_value error_reporting YOUR_INT

in httpd.conf

I want to share this rather straightforward tip as it is rather annoying for new php users trying to understand why things are not working when the error-level is set to (int) "E_ALL" = 0...

Maybe the PHP-developers should make ie error_reporting("E_ALL"); output a E_NOTICE informative message about the mistake?
2005-07-22 19:24:46
In phpinfo() error reporting level display like a bit (such as 4095)

Maybe it is a simply method to understand what a level set on your host
if you are not have access to php.ini file

while (
$bit 0) {
$i 0$n 0$i <= $bit$i pow(2$n), $n++) {
$end $i;
$res[] = $end;
$bit $bit $end;

In $res you will have all constants of error reporting
$res[]=int(16) // E_CORE_ERROR 
$res[]=int(8)    // E_NOTICE 
2005-08-19 13:30:59
The example of E_ALL ^ E_NOTICE is a 'bit' confusing for those of us not wholly conversant with bitwise operators.

If you wish to remove notices from the current level, whatever that unknown level might be, use & ~ instead:

error_reporting($errorlevel & ~E_NOTICE);
//...code that generates notices

^ is the xor (bit flipping) operator and would actually turn notices *on* if they were previously off (in the error level on its left). It works in the example because E_ALL is guaranteed to have the bit for E_NOTICE set, so when ^ flips that bit, it is in fact turned off. & ~ (and not) will always turn off the bits specified by the right-hand parameter, whether or not they were on or off.
2006-04-06 11:51:38
I found some simple mistakes in the functions I posted yesterday, so here are the corrected versions.
And a good advice: never code in the middle of the night ;)

function error2string($value)
$level_names = array(
defined('E_STRICT')) $level_names[E_STRICT]='E_STRICT';
$level_names as $level=>$name)
implode(' | ',$levels);

function string2error($string)
$level_names = array( 'E_ERROR''E_WARNING''E_PARSE''E_NOTICE',
defined('E_STRICT')) $level_names[]='E_STRICT';
$levels as $level)
defined($level)) $value|=(int)constant($level);
2006-05-09 16:32:36
On a shared debugging and production server it is convenient to use
<?php error_reporting(E_ALL); ?>
for debugging.

This will not help in case of parsing errors, so make sure you enable at least E_PARSE in your php.ini. Parse errors should not exist in production scripts.

Still, sometimes your script will not get executed even though no parse error is displayed (just a blank page/ no output at all). As far as I know this only happens when you redeclare a user function or class. 



This prevents your script from running like a parse error, but is in fact a fatal run-time error (E_ERROR). Other fatal run-time errors will allow your script to apply the error_reporting, when it is executed before the 
error occurs (eg. put error_reporting on the first line of code.)
2006-10-04 09:38:42
error_reporting() may give unexpected results if the @ error suppression directive is used.

@include 'config.php';
'';        // non-existent file


will throw an error level E_WARNING in relation to the non-existent file (depending of course on your configuration settings).  If the suppressor is removed, this works as expected.

Alternatively using ini_set('display_errors', 0) in config.php will achieve the same result.  This is contrary to the note above which says that the two instructions are equivalent.
2007-01-19 05:43:51
regarding what vdephily at bluemetrix dot com said ( see )

echo $foobar->field;

also initializes $foobar (as an instance of stdClass), so this code will not cause any notices.
2007-04-04 08:21:58
I had the problem that if there was an error, php would just give me a blank page.  Any error at all forced a blank page instead of any output whatsoever, even though I made sure that I had error_reporting set to E_ALL, display_errors turned on, etc etc.  But simply running the file in a different directory allowed it to show errors!

Turns out that the error_log file in the one directory was full (2.0 Gb).  I erased the file and now errors are displayed normally.  It might also help to turn error logging off.
2008-05-27 04:12:39
this is to show all errors for code that may be run on different versions

for php 5 it shows E_ALL^E_STRICT and for other versions just E_ALL

if anyone sees any problems with it please correct this post

('error_reporting'version_compare(PHP_VERSION,5,'>=') && version_compare(PHP_VERSION,6,'<') ?E_ALL^E_STRICT:E_ALL);
2008-08-10 14:45:14
If you just see a blank page instead of an error reporting and you have no server access so you can't edit php configuration files like php.ini try this:

- create a new file in which you include the faulty script:


- execute this file instead of the faulty script file 

now errors of your faulty script should be reported.
this works fine with me. hope it solves your problem as well!
2008-08-14 09:34:33
Only display php errors to the developer...


Just replace with your ip address.
2009-02-18 08:03:13
It could save two minutes to someone:
E_ALL & ~E_NOTICE  integer value is 6135
2009-03-25 03:54:44
I always code with E_ALL set.
After a couple of pages of
= (isset($_POST['username']) && !empty($_POST['username']))....

I made this function to make things a little bit quicker.  Unset values passed by reference won't trigger a notice.

function test_ref(&$var,$test_function='',$negate=false) {
$stat true;
$var)) $stat false;
    if (!empty(
$test_function) && function_exists($test_function)){
$stat $test_function($var);
$stat = ($negate) ? $stat^$stat;
$test_function == 'empty') {
$stat = empty($var);
$stat = ($negate) ? $stat^$stat;
    elseif (!
function_exists($test_function)) {
$stat false
trigger_error("$test_function() is not a valid function");
$stat = ($stat) ? true false;
$a '';
$b '15';

test_ref($a,'empty',true);  //False
test_ref($a,'is_int');  //False
test_ref($a,'is_numeric');  //False
test_ref($b,'empty',true);  //true
test_ref($b,'is_int');  //False
test_ref($b,'is_numeric');  //false
test_ref($unset,'is_numeric');  //false
test_ref($b,'is_number');  //returns false, with an error.
2009-06-09 17:25:50
see more information about php 5.3 deprecated errors

2010-01-29 15:00:11
Some E_STRICT errors seem to be thrown during the page's compilation process.  This means they cannot be disabled by dynamically altering the error level at run time within that page.

The work-around for this was to rename the file and replace the original with a error_reporting() call and then a require() call.

Ex, rename index.php to, then re-create index.php as:


That allows you to alter the error reporting prior to the file being compiled.

I discovered this recently when I was given code from another development firm that triggered several E_STRICT errors and I wanted to disable E_STRICT on a per-page basis.
2010-06-14 13:23:30
To enable error reporting for *ALL* error messages including every error level (including E_STRICT, E_NOTICE etc.), simply use:

<?php error_reporting(-1); ?>
2010-12-06 04:55:12
Setting error_reporting in your VirtualHost has to be done through a numerical value which is the result of the options you choose summed up from the values of these options, as defined on the constants page for the error management functions: errorfunc.constants

As a result, E_ALL & ~E_NOTICE would be set this way (this automatically excludes E_DEPRECATED AND E_USER_DEPRECATED):

  php_value error_reporting 6135

whereas E_ALL (excluding the deprecated levels) would be set this way:

  php_value error_reporting 6143

The difference between those two values is 8, which is the value of the constant for E_NOTICE.
2011-08-03 23:56:03
It might be a good idea to include E_COMPILE_ERROR in error_reporting. 

If you have a customer error handler that does not output warnings, you may get a white screen of death if a "require" fails.


myErrorHandler($errno$errstr$errfile$errline) {
// Do something other than output message.
return true;

$old_error_handler set_error_handler("myErrorHandler");

"this file does not exist";

To prevent this, simply include E_COMPILE_ERROR in the error_reporting.

2012-02-09 22:50:59
Php >5.4

Creating a Custom Error Handler

function customError($errno, $errstr)
  echo "<b>Error:</b> [$errno] $errstr<br>";
  echo "Ending Script";
2013-10-01 10:56:27
To not display the E_DEPRECATED errors (for example) without changing the rest of the configuration :
error_reporting(error_reporting() & (-1 ^ E_DEPRECATED));
2014-01-07 11:30:42
If you are using the PHP development server, run from the command line via `php -S servername:port`, every single error/notice/warning will be reported in the command line itself, with file name, and line number, and stack trace.

So if you want to keep a log of all the errors even after page reloads (for help in debugging, maybe), running the PHP development server can be useful.
2015-01-03 19:18:47
If you want to see all errors in your local environment, you can set your project URL like "" locally and put that in bootstrap file.

if (substr($_SERVER['SERVER_NAME'], -6) == '.local') {
// or error_reporting(E_ALL);
2015-04-11 02:44:39
The error_reporting() function will return 0 if error suppression is currently active somewhere in the call tree (via the @ operator).
2016-11-12 14:55:51
To expand upon the note by chris at ocproducts dot com. If you prepend @ to error_reporting(), the function will always return 0.

error_reporting(), // value of E_ALL,
@error_reporting() // value is 0
2017-03-14 23:35:04
As for the iMac, Customer Service Number is the best feature of remote access iMac Customer Support Number is not editable during use of the remote access application on Microsoft Windows than can you help with the contact us. If you are facing any issue related to iMac Support Number, it is good service provide 24*7 hours anytime problem with our contact us.
2018-03-10 12:04:02
The Apple iMac Customer Support is one of the best services provides in the world. They provide an all-around for email your pc Help the issues related to iMac Customer Service Number you can solve any problem with the iMac Customer Service Number than just you can contact us.
2018-03-10 12:07:18
I had the problem that if there was an error, php would just give me a blank page.  Any error at all forced a blank page instead of any output whatsoever, even though I made sure that I had error_reporting set to E_ALL, display_errors turned on, etc etc.  But simply running the file in a different directory allowed it to show errors!

Turns out that the error_log file in the one directory was full (2.0 Gb).  I erased the file and now errors are displayed normally.  It might also help to turn error logging off.
2018-04-16 20:34:07
The Apple iMac Customer Support is extraordinary compared to other administrations gives on the planet. They give an overall to email your pc Help the issues identified with iMac Customer Service Number you can tackle any issue with the iMac Customer Service Number than just you can reach us.
2018-04-16 20:38:59

    Поддержать сайт на родительском проекте КГБ