웹모아
웹모아[손님] 검색   로그인 / 회원가입    



 
환경설정
 


error_reporting
  2007-03-20 15:30:49 댓글:(0)   조회:1795




error_reporting

(PHP 3, PHP 4 , PHP 5)

error_reporting -- Sets which PHP errors are reported

Description

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.

error_reporting() sets PHP's error reporting level, and returns the old level. The level parameter 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.

예 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
);

?>

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

value constant
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

주의

With PHP > 5.0.0 E_STRICT with value 2048 is available. E_ALL does NOT include error levelE_STRICT.

See also the display_errors directive and ini_set().



add a note add a note User Contributed Notes
error_reporting
nate at codetrail dot com
01-Dec-2005 04:42
If you also using set_error_handler to catch errors, trying to set the level of error reported by using error_reporting has no effect.  All errors will be caught by set_error_handler regardless of what you try to set using error_reporting.
DarkGool
19-Aug-2005 05:30
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

<?
$bit
= ini_get('error_reporting'
);
while (
$bit > 0
) {
   for(
$i = 0, $n = 0; $i <= $bit; $i = 1 * 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
...
fredrik at demomusic dot nu
22-Jul-2005 11:24
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:
<?
ini_set
("error_reporting", E_YOUR_ERROR_LEVEL
);
echo
ini_get("error_reporting"
);
?>

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?
alex at modem-help dot com
24-Jun-2005 12:22
Centos4 (Apache/2.0.52, php-4.3.9)

Maintaining development + production sites side-by-side is  possible. Obviously, the production site wants all error-reporting display switched off, whilst the development site is the total reverse. Unfortunately, the php.ini file is global.

Using `ini_set("display_errors","1");' is not possible (ref: 12-Feb-2005 12:28 below) as any fatal errors in the script mean that it (and included scripts) never get acted upon (see php.net/manual/en/ref.errorfunc.php#ini.display-errors).

Unfortunately the suggestion from Fernando Piancastelli (ref: 13-Dec-2004 09:23) did not work for me either. The following *did* work, and allows parse-errors to be displayed on the development site:

php.ini:
error_reporting  =  ~E_ALL
display_errors = Off
display_startup_errors = Off

within an Apache Virtual Host in httpd.conf:
php_flag  display_errors        on
php_flag  display_startup_errors on
php_value error_reporting        2047

The above *should* be surrounded with `<IfModule mod_php4.c> ... </IfModule>' but that did not work either.
phpfanat at yandex dot ru
22-Feb-2005 05:03
If you get a weird mysql warnings like "Warning: mysql_query() [http://www.mysql.com/doc]: 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
ini_set("mysql.trace_mode","Off");
in your script

And, as of my opinion, it should be NOTICE, not WARNING level.
vdephily at bluemetrix dot com
22-Feb-2005 11:40
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 :
<?php
error_reporting
(E_ALL
);

$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
?>
11-Feb-2005 05:55
Under jjuffermans' note, the editors posted the following:

"Instead of using @ to suppress errors if the file does not exist you should do a conditional include:

if (is_file("nosuchfile.php")) {
 include_once("nosuchfile.php");
}"

This is rather obvious, but has an even more obvious problem: is_file doesn't check on the include_path, which one assumes include_once is highly likely to be using.

While there are any number of kludgy workarounds which can be employed to overcome this problem, it's a structural problem in PHP and should be fixed. Preferably @ should only suppress a file not found error, but not any errors inside the included file if it is found, or failing that at the least is_file or file_exists should have the option to look on the include_path for the file.
Fernando Piancastelli
13-Dec-2004 09:23
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.
dnirvine[at]gmail[dot]com
14-Nov-2004 08:21
<?php
# 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

php_error_reporting=
4

# 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
.

[
code
]
// setting PHP error reporting
switch(getinivar('php_error_reporting'
)) {
case
0: error_reporting(0
); break;
case
1: error_reporting(E_ERROR | E_WARNING | E_PARSE
); break;
case
2: error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE
); break;
case
3: error_reporting(E_ALL ^ (E_NOTICE | E_WARNING
)); break;
case
4: error_reporting(E_ALL ^ E_NOTICE
); break;
case
5: error_reporting(E_ALL
); break;
default:
  
error_reporting(E_ALL
);
}
[/
code
]
?>
I'll have to start using this from now on!  Be much easier than having error_reporting(0) and trying to switch to find errors.  Thanks.
ferozzahid [at] usa [dot] com
08-Sep-2004 11:31
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

php_error_reporting=4

# 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.

[code]
// setting PHP error reporting
switch(getinivar('php_error_reporting')) {
case 0: error_reporting(0); break;
case 1: error_reporting(E_ERROR | E_WARNING | E_PARSE); break;
case 2: error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); break;
case 3: error_reporting(E_ALL ^ (E_NOTICE | E_WARNING)); break;
case 4: error_reporting(E_ALL ^ E_NOTICE); break;
case 5: error_reporting(E_ALL); break;
default:
   error_reporting(E_ALL);
}
[/code]

Feroz Zahid.
simon at firepages dot com dot au
23-Nov-2003 09:04
I needed to get a string representation of the integer value returned by ini_get( 'error_reporting' ) ;& this is what I ended up with if its of any use ... It appears to work ok.

<?
$err
=array(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 '
);

function
foo( &$intval
){
  
$x=2047
;
   while(
$x > 0
){
       if(
$x < $intval
){
          
$intval = $intval - abs( $x
) ;
           return
abs( $x
) ;
       }
      
$x = ceil( $x / 2
) ;
   }
}

function
bar( $intval ,$err
){
   while(
$intval > 0
){
       if( isset(
$err[$intval
] ) ){
          
$array[] = $err[$intval
];
           break;
       }
      
$rets = foo( $intval
) ;
      
$array[] = $err[$rets
];
   }
   return
$array
;
}

$intval = 2047 - (int)ini_get( 'error_reporting'
) ;
echo
'E_ALL & ~ ( ' .@implode( ' | ' , bar( $intval , $err ) ) . ' ) '
;
?>
hughjonesd at yahoo dot co dot uk
04-Sep-2003 04:49
In response to peterdodge below: sometimes it's a good idea to throw errors, because they warn the developer (or user) that something is wrong. It might be better to throw an error, but to set up a good error handler in order to display a useful error page or message to the reader. If you're clever, you can even set up a stack of error handlers, and have errors "thrown" and "caught" at different points in your script.
peterdodge at liquidfirestudios.com
21-May-2003 07:33
Try to avoid the use of E_USER_* errors when you can, as the script can better handle bad input better with conditional branching:

# e.g. user entered "foo"

$bad_data = "foo";

if ($input == $bad_data)
{
   myErrorHandler("Gave bad data $input");
}
else
{
   processData($input);
}

Also, as a programming practice try to use E_NOTICE whenever possible to catch undefined variables.
jernberg at fairytale dot se
27-Feb-2003 11:27
tip: if you want your error_reporting()-setting to work with your own error handler you could simply check the error number against the current error bitmask.

function myErrorHandler( $errno, $errstr, $errfile, $errline )
{
  $replevel = error_reporting();
  if( ( $errno & $replevel ) != $errno )
  {
   // we shall remain quiet.
   return;
  }
  echo( "error....." );
}
ronald at segment dot info
11-Feb-2003 04:09
Function translateErrorReportingConstant2String()
{
 $current = error_reporting();
 $out = "";

  if (($current & E_ERROR          ) == E_ERROR          ){ $out .=" E_ERROR          | "; }
  if (($current & E_WARNING        ) == E_WARNING        ){ $out .=" E_WARNING        | "; }
  if (($current & E_PARSE          ) == E_PARSE          ){ $out .=" E_PARSE          | "; }
  if (($current & E_NOTICE        ) == E_NOTICE        ){ $out .=" E_NOTICE          | "; }
  if (($current & E_CORE_ERROR    ) == E_CORE_ERROR    ){ $out .=" E_CORE_ERROR      | "; }
  if (($current & E_CORE_WARNING  ) == E_CORE_WARNING  ){ $out .=" E_CORE_WARNING    | "; }
  if (($current & E_COMPILE_ERROR  ) == E_COMPILE_ERROR  ){ $out .=" E_COMPILE_ERROR  | "; }
  if (($current & E_COMPILE_WARNING) == E_COMPILE_WARNING){ $out .=" E_COMPILE_WARNING | "; }
  if (($current & E_USER_ERROR    ) == E_USER_ERROR    ){ $out .=" E_USER_ERROR      | "; }
  if (($current & E_USER_WARNING  ) == E_USER_WARNING  ){ $out .=" E_USER_WARNING    | "; }
  if (($current & E_USER_NOTICE    ) == E_USER_NOTICE    ){ $out .=" E_USER_NOTICE    | "; }
  if (($current & E_ALL            ) == E_ALL            ){ $out .=" E_ALL            | "; }
 return $out;
 }
}
jjuffermans at chello dot com
05-Jan-2003 02:47
[Editor's Note]
Instead of using @ to suppress errors if the file does not exist you should do a conditional include:

if (is_file("nosuchfile.php")) {
 include_once("nosuchfile.php");
}


Note that when you use the @ to suppress the error of an include file that couldn'd be found, like so:

  @include("nosuchfile.php");

It also suppresses all the parse errors generated in "nosuchfile.php" if it does exist.

It took us a long time before we discovered why we weren't  getting any parse errors... This is it.

Personally, I don't like this... Maybe it can be changed in a future php version? :)

Coditor
sreid at sea-to-sky dot net
18-Nov-2002 09:16
It seems that using E_NOTICE (included with E_ALL) is the only way to get warnings about undefined variables. For example, if you type $soemthing when you mean $something, you may not get any message about it unless you use E_NOTICE level reporting.

The problem is, at that level of reporting you also get notices about array indexes that have not been set. This means lots of warnings when using $_GET['formvariable'] and such. You can check isset($_GET['formvariable']) first, but that gets annoying, especially when it is redundant to stricter input validation you need to do anyway.

The only solution I have found is to use set_error_handler() to register a custom error reporting function to report everything except where the error string starts with "Undefined index:". Then I call error_reporting(E_ALL). This seems to be the best compromise.

function error_handler($errno, $errstr, $errfile, $errline, $errctx) {
   if ($errno == E_NOTICE && substr($errstr, 0, 17) == "Undefined index: ") return;
   echo "\nerror_handler:\n\terrno=$errno\n\terrstr=$errstr\n";
   echo "\terrfile=$errfile\n\terrline=$errline\n";
   if ($errno & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR)) die();
}
set_error_handler("error_handler");
error_reporting(E_ALL);
rbt at zort.ca
10-Feb-2002 04:25
It should be noted that in apache.conf files the defined values (constants) don't work.  For E_ALL logging, one would use:

php_admin_value error_reporting 2047
25-Mar-2001 05:32
It seems that parse errors will be handled internally even if you've designated your own error handler; that is, your error-handling function will /not/ be called on a parse error.
cgi at harrison dot org
11-Dec-2000 11:59
[Editor's Note: The error suppression operator (@)can be used to suppress errors for a single expression. To use the operator, place it in front of the expression that you wish to suppress error reporting for. Basic use is:

$fp = @ fopen ('non-existant.file', 'r');

 See the url below for details.]

Error Suppression Operator - Info
http://www.php.net/manual/language.operators.errorcontrol.php
j dot schriver at vindiou dot com
03-Oct-2000 06:37
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;

 -zak@php.net]
durchholz at sourceforge dot net
25-Aug-2000 10:13
Here's how to temporarily lower the error reporting level:

$old_error_reporting = error_reporting(E_ALL & ~(E_WARNING | E_NOTICE | ...));
... do whatever you want to do in less verbose mode
error_reporting($old_error_reporting);
03-Feb-2000 07:31
The E_NOTICE error reporting level reports the use of undefined variables as an error.

For example:
error_level (E_ALL); # Set error reporting to highest level
if ($foo)            # This will generate an error
  print "bar";      # because $foo is not defined

To avoid this behavior, use isset to test if the given
variable has been defined.

For example:
error_level (E_ALL);
if (isset ($foo))
   print "bar";
webmaster at l-i-e dot com
21-May-1999 09:13
[Editor's Note: E_ALL will contain the result of OR'ing all of the applicable error constants together. For PHP 3, this will be the first 4 E_xxx constants.  For PHP 4, this will be all constants. ]

There is also an E_ALL which is the first 4 E_xxx added up for you...




 댓글 (0)


환경설정
페이지: 1 / 2   


   PHP.INI에서의 세션 관련 설정5216
   [PHP] $_SERVER3539
   php 에서 세션시간설정1354
   업로드 용량과 관련한 php.ini 파일 설정1302
   mbstring - PHP 확장모듈을 추가하는 방법1351
     [RE] mbstring - PHP 확장모듈을 추가1473
   타도메인간 쿠키 공유하기1726
   home 데이타 백업 스크립트1307
   cron 이용 일정시간마다 php문실행2118
   cron, crontab, PHP 소스 자동실행, 1582
   crontab 에서 php 파일 실행이 가능한지요?1426
   crontab php 스크립트 실행문제입니다.(1) 1302
   2차 도메인과의 세션고유1530
   POST로 값을 넘길때, 만료된 페이지입니다 문제의(홈마스타)3120
   세션(로그인)시간 무한대로 늘리기 초간단 초보용(홈마스타)(2) 1409
   php mysql 세션 관리(홈마스타)2667
   세션을 DB로 관리하기 + 쪽지 확인하기(홈마스타)(1) 1610
   브라우져를 종료해도 세션이 그대로 살아있어요(홈마스타)2465
   PHP에서 세션 사용하기(홈마스타)1404
   [설치/설정] PHP 파일업로드시 일정용량 이상 업(홈마스타)1272
   php.ini 값 설정가능한 범위 알아보기(홈마스타)1537
   PHP 슈퍼전역변수 들의 종류(홈마스타)19582
   쿠키공유를 위한 헤드값(홈마스타)1416
   php.ini 설정하기(홈마스타)1425
   php.ini (V4.2.3) - III(홈마스타)1399
   php.ini (V4.2.3) - II(홈마스타)1438
   환경을 실행중에 임시로 바꾸기(홈마스타)1299
   php.ini (V4.2.3)(홈마스타)1500
error_reporting(홈마스타)1796
   경과만료 페이지 없애기(홈마스타)1634
[1]  [2]  

복수단어 검색은 공백(space)로 구분해 주세요. 1




 
최근 글
[손님]

인기 글
[손님]
[깊은연못] KMFM - 24시간 연주곡
[예진아씨] 자료없음