Hiding Deprecated Error Message Not Working - php

I was getting this error since I was using a third party application using mysql_ prefix.
Deprecated: The mysql extension is deprecated and will be removed in
the future: use mysqli or PDO instead in /path/to/filename.php on line
123
So i tried to hide this error by editing my php.ini file. I have tried adding
error_reporting = E_ALL ^ E_DEPRECATED;
But that didn't work.
So I tried this
error_reporting(E_ALL ^ E_DEPRECATED);
That too didn't work. What may be the issue? Is it with my php.ini file, or am I doing it wrong. Please let me know the correct method to hide this deprecated error message (or what was wrong with the methods i used).

You need to logically AND the negated E_DEPRECATED flag in order to disable it:
error_reporting(E_ALL &~ E_DEPRECATED);

Try this to deprecate error messages of 3rd third party tools.
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);

Related

Parsing issue when using PHP Readability Library [duplicate]

My server is running PHP 5.3 and my WordPress install is spitting these errors out on me, causing my session_start() to break.
Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 647
Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 662
Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 669
Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 676
Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 712
This is annoying, but I do not want to turn off on screen error reporting. How do I disable these bothersome deprecated warnings?
I am running WordPress 2.9.2.
You can do it in code by calling the following functions.
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
or
error_reporting(E_ALL ^ E_DEPRECATED);
To only get those errors that cause the application to stop working, use:
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING | E_DEPRECATED));
This will stop showing notices, warnings, and deprecated errors.
I needed to adapt this to
error_reporting = E_ALL & ~E_DEPRECATED
You have to edit the PHP configuration file. Find the line
error_reporting = E_ALL
and replace it with:
error_reporting = E_ALL ^ E_DEPRECATED
If you don't have access to the configuration file you can add this line to the PHP WordPress file (maybe headers.php):
error_reporting(E_ALL ^ E_DEPRECATED);
I just faced a similar problem where a SEO plugin issued a big number of warnings making my blog disk use exceed the plan limit.
I found out that you must include the error_reporting command after the wp-settings.php require in the wp-config.php file:
require_once( ABSPATH .'wp-settings.php' );
error_reporting( E_ALL ^ ( E_NOTICE | E_WARNING | E_DEPRECATED ) );
by doing this no more warnings, notices nor deprecated lines are appended to your error log file!
Tested on WordPress 3.8 but I guess it works for every installation.
All the previous answers are correct. Since no one have hinted out how to turn off all errors in PHP, I would like to mention it here:
error_reporting(0); // Turn off warning, deprecated,
// notice everything except error
Somebody might find it useful...
In file wp-config.php you can find constant WP_DEBUG. Make sure it is set to false.
define('WP_DEBUG', false);
This is for WordPress 3.x.
I tend to use this method
$errorlevel=error_reporting();
$errorlevel=error_reporting($errorlevel & ~E_DEPRECATED);
In this way I do not turn off accidentally something I need
If PHP warnings are breaking things in WordPress, but you still want to know what the warnings are, you can disable displaying PHP errors/warnings and only send them to the log file:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'WP_DEBUG_LOG', true );
this error occur when you change your php version: it's very simple to suppress this error message
To suppress the DEPRECATED Error message, just add below code into your index.php file:
init_set('display_errors',False);

How to disable deprecated warnings in runtime php?

I want to supress warning from this trigger_error('Deprecated', E_USER_DEPRECATED); in runtime. From I have read I can use error_reporting(E_ALL & -E_USER_DEPRECATED & -E_DEPRECATED);. But that does not work. I tried if error_reporting works in general by using error_reporting(0). This works. What did I miss? I did not find another way to solve my problem. And did not notice that this way does not work for someone else.
My code which does not suppress deprecated warning:
error_reporting(E_ALL & -E_USER_DEPRECATED);
trigger_error('Deprecated', E_USER_DEPRECATED);
Php version: 7.0.14.
You have a syntax error in the value for error_reporting(). To exclude certain errors you need to use the tilde symbol ~ instead of the dash -:
error_reporting(E_ALL & ~E_USER_DEPRECATED);
// ^ this one
trigger_error('Deprecated', E_USER_DEPRECATED);

i have faced an error in wordpress plugin

i am developing a site in WordPress and, i am using PHP version 5.6 and i have faced this error:
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/c118209438/public_html/wp-includes/wp-db.php on line 1578
i want to hide this error , for that i used these lines but it does not give me appropriate output ...
error_reporting(0)
error_reporting(E_ALL &~ E_DEPRECATED);
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED
thanks for advance ...

PHP error_reporting either on or off

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?
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.
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.
Solution :
ini_set("display_errors",'off');
Use this in your php script.It will hide warnings coming in your page.
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);
?>

Why do I continue to receive PHP Deprecated errors despite this ini setting?

I've set my error_reporting to
error_reporting = E_ALL & ~E_DEPRECATED ^ E_STRICT
in php.ini. The numerical value according to phpinfo() is 22527.
However we are still logging plenty of
[01-Oct-2011 13:06:36] PHP Deprecated: Assigning the return value of new by reference is deprecated in /htdocs/www/site/core.php on line 2381
[01-Oct-2011 13:06:36] PHP Deprecated: Function set_magic_quotes_runtime() is deprecated in /htdocs/www/site/core.php on line 1538
I've seen a few other questions about this, but not with any solutions I haven't tried. We're using (an outdated version of) VBulletin. Could that be changing the setting?
I see now that VBulletin's forumdisplay.php has a line
error_reporting(E_ALL & ~E_NOTICE);
Commenting this out didn't change anything.

Categories