Php 生成oid失败,error_reporting

用户评论:

[#1]

qeremy ! gmail [2015-04-10 23:44:39]

If you want to see all errors in your local environment, you can set your project URL like "foo.com.local" locally and put that in bootstrap file.

[#2]

Rash [2015-01-03 17:18:47]

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.

[#3]

Marc17 [2014-01-07 09:30:42]

To not display the E_DEPRECATED errors (for example) without changing the rest of the configuration :

error_reporting(error_reporting() & (-1 ^ E_DEPRECATED));

[#4]

polecat1 [2013-12-13 16:01:58]

Most of you know that a script can give different results online compared to your local machine (PHP versions, settings). Nobody wants to see an error message on your online website, like "Access denied for user 'YOURUSERNAME'@'localhost' (using password: YOURPASSWORD)". But sometimes we do need this information on our online site for debugging. Here's a little trick.

On your local machine for your own browser create a cookie, something like:

setcookie ("your-website.com-testing", "1", time()+60*60*24*300);

Then in all your pages (or in includes) add the following line:

if (!isset($_COOKIE["your-website.com-testing"])) {

error_reporting(0);

}

This way errors will be reported ONLY when the page is displayed in YOUR browser.

[#5]

forcemdt [2013-10-01 07:56:27]

Php >5.4

Creating a Custom Error Handler

set_error_handler("customError",E_ALL);

function customError($errno, $errstr)

{

echo "Error: [$errno] $errstr
";

echo "Ending Script";

die();

}

[#6]

teynon1 at gmail dot com [2012-02-09 20:50:59]

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.

Example:

error_reporting(E_ERROR|E_WARNING|E_PARSE);

functionmyErrorHandler($errno,$errstr,$errfile,$errline) {// Do something other than output message.returntrue;

}$old_error_handler=set_error_handler("myErrorHandler");

require"this file does not exist";?>

To prevent this, simply include E_COMPILE_ERROR in the error_reporting.

error_reporting(E_ERROR|E_WARNING|E_PARSE|E_COMPILE_ERROR);?>

[#7]

ywarnier at beeznest dot org [2011-08-03 20:56:03]

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: http://www.php.net/manual/en/errorfunc.constants.php

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.

[#8]

rojaro at gmail dot com [2010-12-06 02:55:12]

To enable error reporting for *ALL* error messages including every error level (including E_STRICT, E_NOTICE etc.), simply use:

[#9]

keithm at aoeex dot com [2010-06-14 10:23:30]

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 index.inc.php, then re-create index.php as:

error_reporting(E_ALL& ~(E_STRICT|E_NOTICE));

require('index.inc.php');?>

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.

[#10]

roberto at spadim dot com dot br [2010-01-29 13:00:11]

see more information about php 5.3 deprecated errors

http://php.net/manual/en/migration53.deprecated.php

[#11]

misplacedme at gmail dot com [2009-06-09 14:25:50]

I always code with E_ALL set.

After a couple of pages of

$username= (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.

if(!isset($var))$stat=false;

if (!empty($test_function) &&function_exists($test_function)){$stat=$test_function($var);$stat= ($negate) ?$stat^1:$stat;

}

elseif($test_function=='empty') {$stat= empty($var);$stat= ($negate) ?$stat^1:$stat;

}

elseif (!function_exists($test_function)) {$stat=false;trigger_error("$test_function() is not a valid function");

}$stat= ($stat) ?true:false;

return$stat;

}$a='';$b='15';test_ref($a,'empty',true);//Falsetest_ref($a,'is_int');//Falsetest_ref($a,'is_numeric');//Falsetest_ref($b,'empty',true);//truetest_ref($b,'is_int');//Falsetest_ref($b,'is_numeric');//falsetest_ref($unset,'is_numeric');//falsetest_ref($b,'is_number');//returns false, with an error.?>

[#12]

ecervetti at orupaca dot fr [2009-03-25 01:54:44]

It could save two minutes to someone:

E_ALL & ~E_NOTICE  integer value is 6135

[#13]

Daz Williams (The Northeast) [2009-02-18 06:03:13]

Only display php errors to the developer...

{ini_set('display_errors','On');

}

else

{ini_set('display_errors','Off');

}?>

Just replace 00.00.00.00 with your ip address.

[#14]

info at hephoz dot de [2008-08-14 06:34:33]

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:

error_reporting(E_ALL);ini_set("display_errors",1);

include("file_with_errors.php");?>

- 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!

[#15]

kc8yds at gmail dot com [2008-08-10 11:45:14]

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

ini_set('error_reporting',version_compare(PHP_VERSION,5,'>=') &&version_compare(PHP_VERSION,6,'

[#16]

derek at darkcolors dot com [2008-05-27 01:12:39]

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.

[#17]

antickon AT gmail.com [2007-04-04 05:21:58]

regarding what vdephily at bluemetrix dot com said ( see http://be.php.net/manual/en/function.error-reporting.php#50228 )

<?phpecho $foobar->field;?>

also initializes $foobar (as an instance of stdClass), so this code will not cause any notices.

[#18]

Alex [2007-01-19 03:43:51]

error_reporting() may give unexpected results if the @ error suppression directive is used.

include'foo.bar';// non-existent file?>

config.php

error_reporting(0);?>

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.

[#19]

silvan at NOSPAM dot example dot com [2006-10-04 06:38:42]

On a shared debugging and production server it is convenient to use

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.

eg.

error_reporting(E_ALL);

functiona(){}

functiona(){}?>

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

[#20]

Chris [2006-05-09 13:32:36]

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

{$level_names= array(E_ERROR=>'E_ERROR',E_WARNING=>'E_WARNING',E_PARSE=>'E_PARSE',E_NOTICE=>'E_NOTICE',E_CORE_ERROR=>'E_CORE_ERROR',E_CORE_WARNING=>'E_CORE_WARNING',E_COMPILE_ERROR=>'E_COMPILE_ERROR',E_COMPILE_WARNING=>'E_COMPILE_WARNING',E_USER_ERROR=>'E_USER_ERROR',E_USER_WARNING=>'E_USER_WARNING',E_USER_NOTICE=>'E_USER_NOTICE');

if(defined('E_STRICT'))$level_names[E_STRICT]='E_STRICT';$levels=array();

if(($value&E_ALL)==E_ALL)

{$levels[]='E_ALL';$value&=~E_ALL;

}

foreach($level_namesas$level=>$name)

if(($value&$level)==$level)$levels[]=$name;

returnimplode(' | ',$levels);

}?>

{$level_names= array('E_ERROR','E_WARNING','E_PARSE','E_NOTICE','E_CORE_ERROR','E_CORE_WARNING','E_COMPILE_ERROR','E_COMPILE_WARNING','E_USER_ERROR','E_USER_WARNING','E_USER_NOTICE','E_ALL');

if(defined('E_STRICT'))$level_names[]='E_STRICT';$value=0;$levels=explode('|',$string);

foreach($levelsas$level)

{$level=trim($level);

if(defined($level))$value|=(int)constant($level);

}

return$value;

}?>

[#21]

dave at davidhbrown dot us [2006-04-06 08:51:38]

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:

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

[#22]

DarkGool [2005-08-19 10:30:59]

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

...

[#23]

fredrik at demomusic dot nu [2005-07-22 16:24:46]

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

echoini_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?

[#24]

phpfanat at yandex dot ru [2005-02-22 09:03:13]

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.

[#25]

vdephily at bluemetrix dot com [2005-02-22 03:40:47]

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 :

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?>

[#26]

Fernando Piancastelli [2004-12-13 13:23:02]

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.

[#27]

ferozzahid [at] usa [dot] com [2004-09-08 04:31:00]

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.

case0:error_reporting(0); break;

case1:error_reporting(E_ERROR|E_WARNING|E_PARSE); break;

case2:error_reporting(E_ERROR|E_WARNING|E_PARSE|E_NOTICE); break;

case3:error_reporting(E_ALL^ (E_NOTICE|E_WARNING)); break;

case4:error_reporting(E_ALL^E_NOTICE); break;

case5:error_reporting(E_ALL); break;

default:error_reporting(E_ALL);

}?>

Feroz Zahid.

[#28]

j dot schriver at vindiou dot com [2000-10-02 23:37:18]

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]

[#29]

webmaster at l-i-e dot com [1999-05-21 14:13:31]

[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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值