Turning off Deprecation warnings in PHP.ini file WAMP - php

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.

Related

E_ALL & ~E_DEPRECATED not working as expected

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

PHP 5.5 shows internal server instead of displaying errors

I have updated my PHP version 5.3 to 5.5 and currently it starts to display internal server error instead of showing errors.
My php.ini settings configurations are as below:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
I have already trial-and-error'ed various options available at stack overflow:
error_reporting = E_ALL
error_reporting = E_NOTICE
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
Try to set display_errors to On in your php.ini. See http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors.
With reference http://www.php.net/manual/en/errorfunc.configuration.php and fnc, I have used in two ways as given below, both of them work fine at my end.
Option 1: Add the following line at the end of php.ini file or change value if it is existed as:
display_errors = On
Option 2: Change settings run time, add below line at the top of PHP script file.
<?php
if (!ini_get('display_errors')) {
ini_set('display_errors', '1');
}
?>

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

Why are my PHP errors not displaying?

Here is my php.ini and I have restarted the httpd process several times while messing around with this, however no errors are being displayed, only a blank page.
error_reporting = E_ALL & E_STRICT
display_errors = On
In dev, we use this:
error_reporting = E_ALL | E_STRICT

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.

Categories