Can PHP cancel an error notice in a PHP file, not in php.ini?
As I know, we can set
error_reporting = E_ERROR
display_errors = Off
in php.ini, for a globe setting.
But I only want to cancel an errors notice in one PHP file, not all the pages. when something will print in the page like:
Warning: getimagesize(CU1402715579480Bv-300x286--50x50.jpg) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.1 505 HTTP Version Not Supported...
Can we close an errors notice on the page, like <php 开发者_如何学Goset_time_limit(0); ?>
or <php date_default_timezone_set('America/Los_Angeles'); ?>
Yes, see
error_reporting()
to suppress the errorerror_get_last()
to get the error message afterwards if necessary
Related: The error handling functions chapter in the manual.
Yes you can, see example:
if (!ini_get('display_errors')) {
ini_set('display_errors', 1);
}
Please read:
http://php.net/manual/en/function.ini-set.php
Besides setting error_reporting(E_ERROR)
in the script, you can also individually suppress errors for specific functions using the shut up operator:
@getimagesize("http://wrong.wrong.wrg/nonexist.png");
Though in your case you might want to set protocol_version
by requesting the file separataly with http context options, http://www.php.net/manual/en/context.http.php - this would eliminate the actual error. (Or as lazy alternative use a HTTP class/library.)
In your specific script, which generate the notice, you can put this:
error_reporting(E_ALL ^ E_NOTICE);
All the error (E_ALL) except notices (E_NOTICE) will be shown.
Aka.
error_reporting(E_ALL ~E_NOTICE); maybe a syntax error over here i'm not pretty sure though
精彩评论