Reputation: 744
I'm having trouble turning off deprecated warnings for a short period of time. They're coming from a junk-pile script that I'm forced to work on for a while, wherein they use preg_replace with the /e modifier excessively. Rather than go and fix all the places that do this, it seemed like a better idea to turn off deprecated warnings while I'm working on it.
The problem, oddly enough, is that the error_reporting function at the beginning said script seems to have only an "On/Off" effect. That is, I can turn reporting fully off with error_reporting(0)
, and I can have it all on with something like error_reporting(E_ALL)
. But using any of the following options has no affect. I still get some 100+ deprecated warnings at the top of my page.
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
error_reporting(E_ALL & ~E_DEPRECATED);
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
I've verified that my php.ini file is set to E_ALL & ~E_DEPRECATED)
(24575), and it shows as such in phpinfo(). The .htaccess file in the project root is empty. Why there even is one, I don't know.
PHP 5.5.9-1ubuntu4.4
Any ideas?
Upvotes: 0
Views: 3025
Reputation: 685
I'm super late to this, but I've seen this issue more than once and finally tracked down my issue not listed here yet. In my setup, I have attached a global error/exception handler to the process using CarbonPHP; I am the author for full disclosure. Below is the browser output during a WordPress initialization. We see that an E_DEPRECATED
is being thrown even though it is not in the list of errors we should be catching. This list is generated at an error time in the handler function. The key here is actually in the first example in the documentation for PHP's internal global exception handler.
This is the beginning snippet from that example.
// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting, so let it fall
// through to the standard PHP error handler
return false;
}
// $errstr may need to be escaped:
$errstr = htmlspecialchars($errstr);
switch ($errno) {
case E_USER_ERROR:
echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
echo " Fatal error on line $errline in file $errfile";
echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
echo "Aborting...<br />\n";
exit(1);
case E_USER_WARNING:
echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
break;
case E_USER_NOTICE:
echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
break;
default:
echo "Unknown error type: [$errno] $errstr<br />\n";
break;
}
/* Don't execute PHP internal error handler */
return true;
}
The first if statement suggests all errors will be thrown to the global handler despite the reporting level. It seems your responsibility to filter out the unneeded Errors based on level.
IMHO, on the one hand, there is an overhead calling the global handler when it is not needed. Still, since any plugin/method can change the error level, which causes a global change, you can fall back to your original intentions despite the currently set error level. This is very useful and is worth setting up for your project.
Upvotes: 0
Reputation: 15301
I would say there is probably another page or script that is being included that is setting error_reporting to a different value. You can call error_reporting()
with no args to get the current value. Set it to something and check that the value hasn't changed after including other files.
Upvotes: 2
Reputation: 724
Other interesting options for that function:
<?php
// 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);
// For PHP >=5.3 use: E_ALL & ~E_NOTICE
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>
Upvotes: 0
Reputation: 27192
Solution :
ini_set("display_errors",'off');
Use this in your php script.It will hide warnings coming in your page.
Upvotes: 0
Reputation: 29
error_reporting(E_ALL | E_STRICT);
just says "hey, log these kinds of errors/warning/notice"
I think you will need -
ini_set('display_errors', '0');
Try it out.
Upvotes: 0