How to disable deprecated warnings in runtime php? - 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);

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

Confusion regarding the elvis operator in PHP [duplicate]

I have a development version of PHP on Apache. I moved it to production and got this weird notices in my website. I don't have it on development version. How to enable these notices on my development version of website to fix them?
If you have access to your php.ini, then Björn answer is the way to go.
However, if you don't, or if you want to change a particular script / project error level, do this at the beginning of your code:
ini_set('display_errors', 1);
// Enable error reporting for NOTICES
error_reporting(E_NOTICE);
You can see which levels are available for error_reporting here: http://us2.php.net/manual/en/function.error-reporting.php.
It's always a good practice not to show any errors on production environments, but logging any weird behaviors and sending by mail to the administrator. NOTICES should only be enabled on development environments.
Change your php.ini file, the line that says error_reporting, to E_ALL.
I.e:
error_reporting = E_ALL
Seb is right, though you really should use constant for error_reporting().
error_reporting(E_NOTICE);
You can use bitwise operations to pick exactly the messages you want to display. For example:
// notices and warnings
error_reporting(E_NOTICE | E_WARNING);
// everything except errors
error_reporting(E_ALL ^ E_ERROR);

Hiding Deprecated Error Message Not Working

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

PHP built in webserver error reporting

I'm using the built in PHP server and I'd like to suppress the strict warnings. In my php.ini file i have:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
...but it is still printing strict and deprecated notices. I verified that I was editing the correct ini file by checking a page with phpinfo().
In the built in webserver documentation, there is no mention of special error reporting rules.
I have also tried this:
error_reporting(E_ALL ^ E_STRICT ^ E_DEPRECATED);
ini_set("display_errors", "off");
print "changed stuff";
"changed stuff" is printed, along with strict and deprecated notices.
What do I need to do to suppress these errors in the PHP built in webserver? (Can this be done?)
Try changing like this [Reports all errors except STRICT ]
Through Code
<?php
error_reporting(E_ALL ^ E_STRICT);
Through PHP.ini
error_reporting = E_ALL ^ E_STRICT
I searched through my code (it's a very old codebase) and found several instances where the error reporting was manually set. Once i removed those it worked.
Check your files for error_reporting calls

How to solve the use of deprecated function ereg() of PHP 5.3.0 in Drupal 6.13

Anyone knows how to solve the error below?
Deprecated: Function ereg() is deprecated in C:\wamp\www\includes\file.inc on line 895
It is happening after installing Drupal 6.13 on wamp server 2.0i with PHP 5.3.0
Use
preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension);
Instead of
ereg('\.([^\.]*$)', $this->file_src_name, $extension);
Drop your error reporting level below E_DEPRECATED.
PHP 5.3 introduced two new error reporting levels, E_DEPRECATED and E_USER_DEPRECATED and - for the first time in PHP's history - they've started to walk away from older parts of their API. The ereg_* function will still work, but this warning is intended to let you know that "hey, these function will be going away soon, probably in the next major revision).
Just add # in front of the function. e.g.
#ereg()
more issue relating upgraded your web servers which running PHP 5.3.0, pls refer
http://www.rain-forest-forum.com/dotproject-net-installation-issues-t263.html
This is not a Drupal issue.In the Drupal site it is noted that it does not yet support PHP 5.3 and there have been new error flags added to PHP.
Solution1 : You can degarde the PHP version.You can revert back to PHP 5.2.x. As I am unsure of other conflicts with Drupal and PHP 5.3.
Solution2 : However, if you prefer to keep PHP 5.3, you can always suppress the deprecated function errors. In Drupal’s includes/common.inc,
Find the line :
if ($errno & (E_ALL ^ E_NOTICE)) {
And replace it with:
if ($errno & (E_ALL & ~E_NOTICE & ~E_DEPRECATED)) {
This will now always suppress the Deprecated error messages.
One solution is to upgrade the offending sourcecode :-)
It's explained here: http://drupal.org/node/514334#comment-2852940
You can edit you common.inc file to quietly disregard the deprecated error flags. See my post:
http://funkinetics.org/klink/function-ereg-is-deprecated-error-in-drupal-6x-with-php-53/
Looks like the problem is with PHP 5.3.0. You could try downgrading to 5.2.9 as suggested by this drupal link: http://drupal.org/node/514334
Because I don't have time to update legacy code, I addeded following line to php code to suppress warnings.
error_reporting(E_ALL ^ E_DEPRECATED);
this line suppress only deprecated warnings. other errors are shown as usual.

Categories