E_ALL & ~E_DEPRECATED not working as expected - php

Hi am working on a PHP site , it is an old system and i got an error
Deprecated: mysql_connect(): The mysql extension is deprecated and
will be removed in the future: use mysqli or PDO instead...
For now i am not going to change my queries to mysqli or PDO , i simply tried to add
error_reporting = E_ALL & ~E_DEPRECATED
to my php.ini and to remove the deprecated error messages . my php.ini is in C:/xampp/php/php.ini , after i added the value i restarted apache . also i tried with
error_reporting = E_ALL ^ E_DEPRECATED
also i tried with
error_reporting(E_ALL & ~E_DEPRECATED);
in my PHP , common header function , but the messages are showing . i want to remove them .
my MySQL version is 5.6.21
PHP version is 5.6.3
Thank you in advance .

Nothing present in your logs?
A quick browse around the net & SO seems to warrant trying this:
error_reporting(E_ALL ^ E_DEPRECATED);
Which should show all errors except for the deprecated warnings.
Your other option would be to specify only what you want to be displayed in your php.ini file.
error_reporting = |E_ERROR|E_WARNING|.....etc
References
error_reporting();
Predefined constants (flags)
And if the above doesn't work, this answer on ServerFault might clear things up (Providing different options for you to try.)

Maybe you see other error level message. Try:
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT);

Related

I have disabled PHP Error reporting in php.ini but it continues to show in browser

So I have disabled PHP Errors inside my php.ini file (/etc/php5/apache2/php.ini) but they still continue to show in browser. I am running PHP version 5.5.9-1ubuntu4.13 and to do this I used the following:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE & ~E_WARNING
display_errors = Off
display_startup_errors = Off
Examples of errors still showing include:
Warning: Creating default object from empty value ...
and
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in ...
Any help/advice as to why these errors may still be showing would be greatly appreciated. Thanks!
So I finally figured this out, with the help of Ukavi in the comments.
The errors started to display after I had transferred the site from one server to another, and it appears that the first server ran an older version of PHP which is why they did not show up before.
Anyway, the fix. I added this to wp-config.php:
error_reporting(0);
ini_set('display_errors', 'off');
I also did a find in files for ini_set and found a few instances where they had been deliberately activated. As this site is not a solo project I wasn't aware of this!
Thank you for all the advice guys.

Turning off Deprecation warnings in PHP.ini file WAMP

I am working on project # home and using WAMP for development. Currently the php.ini file has the following lines set like this:
error_reporting = E_ALL & ~E_DEPRECATED
display_errors = On
I had hoped in doing so it would prevent deprecation warnings from showing up. However it is not. Is there a way I can adjust error_reporting to ignore deprecated warnings.
Output I am getting currently:
You can use this function :
error_reporting(E_ALL ^ E_DEPRECATED);
http://www.php.net/manual/en/function.error-reporting.php
Or use "#" operator before function name.
#mysql_connect();
In your php.ini file change the following.. (note wamp has 2 different php.ini files so make the changes on both)
from this
error_reporting = E_ALL
to this
error_reporting = E_ALL & ~E_DEPRECATED
I had the same problem. It turned out however, that I edited wrong php.ini file. In my case the correct one was
C:\wamp64\bin\php\php5.6.25\phpForApache.ini
and in this file I have changed this line to:
error_reporting = E_ALL & ~E_DEPRECATED.
It didn't make any difference what I had changed in that "obvious" php.ini file.
Set your error report to
error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
on your php page.
If you want to show all errors except deprecated, then use this setting:
error_reporting = E_ALL ^ E_DEPRECATED
Edit: You could also create a custom error handler to hide only mysql_ deprecation warnings:
set_error_handler(function($errno, $errstr) {
return strpos($errstr, 'mysql_') === 0;
}, E_DEPRECATED);
But please note that mysql_ functions are deprecated. So instead of trying to hide the errors, consider switching to mysqli or PDO.
To hide php errors on WAMP server, Please open php.ini file and find following line of code
error_reporting = E_ALL
and replace it with
error_reporting = E_ALL & ~E_NOTICE
All errors will be hide/disable.

disabling deprecated errors

I want to enable deprecated errors globally but disable them for a specific piece of third-party code, which I don't have the time to fix.
So, I have this in php.ini:
error_reporting = E_ALL & ~E_NOTICE | E_DEPRECATED
and this right before the line where I want to disable the warnings
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
However, it does not work, I'm still getting the warnings for that particular line. If I disable them globally in php.ini it works. I'm using PHP 5.3.10. Any ideas what might be wrong?
Figured it out. The third party code has custom error handler and apparently it's overriding anything you set with error_reporting(). When I commented out the set_error_handler() line, error_reporting() took effect.
Add the below error reporting line in your php.ini:
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED);
Then restart your server and check it.

Disable strict standards in PHP 5.3.8

I am using strict standards option in PHP but I want to disable it because Joomla doesn't like it and I have to use Joomla on my localhost.
In response to another question on this site, this solution was given: E_ALL & ~E_DEPRECATED & ~E_STRICT but this didn't work for me. I think it only works for PHP 5.4 while I am using 5.3.8.
Can anyone tell me what I should use? I am currently using error_reporting(E_ALL & ~E_NOTICE). Also I am using ini_set('display_errors') but there are still errors shown that are related to strict standards.
So how can I disable strict standard errors?
I have the same problem. This is how I fix it in joomla.
Set error_reporting in configuration.php of joomla to "30711" (equal to E_ALL & ~E_NOTICE & ~E_STRICT)
just messed around with this and would like to share my own results. I did not do it runtime using php, I did it in the php.ini file.
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
Remeber to restart the server afterwards ....
I tried thanhtd's solution, but it didn't not work for me. However, I changed the error_reporting value to '1' instead of the default '0' in my configuration.php file for Joomla (2) and that worked. So thanks to thanhtd for getting me on the right path.
to suppress all errors use E_NONE
you might also want to use display_errors(0)

Unable to turn off notice errors in PHP 5.3.2

I recently migrated to PHP 5.3.2, and realized that I am unable to turn off notice errors in my site now. I went to php.ini, and in these lines:
; Common Values:
; E_ALL & ~E_NOTICE (Show all errors, except for notices and coding standards warnings.)
; E_ALL & ~E_NOTICE | E_STRICT (Show all errors, except for notices)
; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors)
; E_ALL | E_STRICT (Show all errors, warnings and notices including coding standards.)
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
; http://php.net/error-reporting
error_reporting = E_ALL & ~E_NOTICE
...I've tried setting everything (and I restart apache each time), but I am unable to get rid of notices.
The only way I'm able to get rid of notice errors is by setting :
display_errors = Off
That is, of course, not something I can do since I need to see errors to fix them, and I would like to see errors on the webpage that I am coding rather than log them somewhere.
Can someone help? Is this a bug in PHP 5.3.2 or something I am doing wrong?
Thank you very much for your time!
P. S. Also, would anyone know how I can get PHP 5.3.2 to support the .php3 extension?
Okay, I figured what was going wrong. I set error_reporting in my code, which was overwriting the php.ini error_reporting.
Now the reason that that same stuff was working until I upgraded to PHP 5.3.2 was this - in my code, I set the error_reporting command:
error_reporting(6143);
I should've set it as:
error_reporting(E_ALL ^ E_NOTICE);
I'm guessing the meaning of 6143 is different in PHP 5.3.2 compared to in 4.1 (or whatever my earlier version was).
As for the php3 extension, it was to be set in the /etc/httpd/conf.d/php.conf file:
AddHandler php5-script .php .php3
AddType text/html .php
Thank you, sourcez, for your suggestions!
I too faced same error today in my website where i use TCPDF Library to generate PDFs. It was working fine but suddenly i started to get the following error today
Severity: 8192
Message: Imagick::clone method is deprecated .....
Might be the hosting provider updated PHP or Imagick. PHP - 5.4 and Imagick - 3.x
So to get rid of this in my code, i set error_reporting as
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
And this will show the errors but not the deprecated notices. Meanwhile I can change my code to support the new version of Imagick.

Categories