PHP error_reporting either on or off - php

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

Related

Mamp/PHP: how to disable PHP warnings messages about deprecated functions

In my web app my boss wants me to use msql_* php functions but I can't even login because of PHP messages about these deprecated functions. How can I disable them in MAMP? Looking in this forum I've found the following rules to write inside php.ini
error_reporting = E_ALL & ~E_DEPRECATED
display_errors = On
disable_functions = "list of mysqli_* functions"
but this doesn't work. I've written this to all file php.ini of each php version contained in MAMP. The only thing that works is to put
display_errors = Off
but I can't use it like that otherwisw I won't even be able to see my programming/syntax error of other problems.
Here is my php.ini of php 5.6.10 inside /Applications/MAMP/bin/php/php5.6.10/conf/
Do you have any ideas? I know I should use new functions and not deprecated ones but it's not up to me and I can't disable all error messages...
I don't really have a solution for you, I'm sorry.
I did like that : in my .php files I put this code :
error_reporting(E_ALL ^ E_DEPRECATED); // without "~"
ini_set("display_errors", 1);
It seems to work.
Within the TEMATRES program (which is the program I use) there is a configuration file: config.tematres.php. This file has the following line:
Ini_set ('display_errors', 'On');
Error_reporting (E_ALL);
I changed it to:
Ini_set ('display_errors', 'On');
Error_reporting (E_ALL ^ E_DEPRECATED);
And thus I was able to solve the problem.

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.

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 avoid or restrict PHP Error output

My PHP web-app sometimes returns this Fatal error on Line XXX due to reasons like extremely-slow-connection speed. Although, this occurs rarely, like 1 in 1000 times, I want to avoid such output on the browser. I am doing error logging on server side for some functions. So, I don't want to completely disable error reporting. Just that I don't want to display it to the end user.
Various Examples on turning off error_reporting..
<?php
// Turn off all error reporting
error_reporting(0);
// 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);
// 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);
?>
note : You can put or include() it in any file you dont want to explicit errors. Or if you want to totally off it. Go with tweaks in php.ini file.
Lines to find in your php.ini to tweaks and off error_reporting.
ini_set('display_errors', 'On'); //change to Off
error_reporting(E_ALL); // change to 0
FOR FURTHER INFO :: PHP.NET
To disable any error display to the user of your page, set
display_errors = Off
in your php.ini (this is the recommended setting for production websites anyway!) or
ini_set('display_errors', 0);
in your php.
This display_errors setting only affects the output on the webpage; it will not affect a possibly configured logfile; there the messages still would be logged.
See the php documentation on configuring error reporting: http://php.net/manual/en/errorfunc.configuration.php
Note: The error_reporting setting mentioned by other users here, will, to my knowledge, affect all kinds of error reports (i.e. also what is reported to a possibly configured log file). If you set error_reporting to 0, you won't get any log entries as well. If you want to log something to the log file but not show it to the user, the display_errors setting is the way to go.
on the start of that page write
error_reporting(0);
To avoid issues like this you can set the max_execution_time=1024M to avoid slow speed data generation and to hide errors is must likely error_reporting=0 on the php.ini file.
Or simply:
PHP Code
ini_set('max_execution_time',1024M);
error_reporting(0);
PHP Ini Settings
max_execution_time=1024M
error_reporting=0
Hope it helps.
error_reporting(0); only works if you are not using set_error_handler('my_function'). If this is your case, you have suppress the error message in 'my_function'.

wamp - notice undefined offset

How to turn off this error in wamp:
notice undefined offset
I'd like to turn of just this error, but not all errors.
There are two issues at work here. One is what errors PHP reports, and the second is whether or not it displays those errors on the page (as opposed to the apache error log). If you'd like to turn off just NOTICES:
<?php
error_reporting(E_ALL & ~E_NOTICE);
?>
If you'd like to report the notices to your error log but not display them to the user, do this:
<?php
ini_set('display_errors','off');
?>
Note that turning off display errors will stop displaying ALL errors to the end user, and you'll need to look at the error log, usually located in /var/log/httpd/error_log to see any errors while testing.
Have a look at error_reporting().
You could e.g. set the error reporting to
error_reporting(E_ERROR | E_WARNING | E_PARSE)
But better would be to actually check what is the cause of the Notice and fix it. Then you are on the save side.
E_NOTICE
Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
(If you can't fix the code...) You can exclude notices by setting an reporting level x & ~E_NOTICE, e.g.
<?php error_reporting( error_reporting() & ~E_NOTICE );
or in your php.ini (or similar)
error_reporting=E_ALL & ~E_NOTICE
php.ini => error_reporting = E_ALL & ~E_NOTICE
error->notice undefined offset
main thing is remove the error on your script.Programmer always wish to design program which is error free instead of error hiding.
The array vales are not set, so when PHP is trying to access the value of those array keys it encounters an undefined offset.
$new_array = array('1','2','3');//If I have an array
//We can now access:
$new_array[0];
$new_Array[1];
$new_array[2];
//If we try and access
$new_Array[3];
we will get the same error-->error->notice undefined offset
error_reporting(E_ALL);
ini_set('display_errors', 'On');
ini_set('html_errors', 'Off');
:D
Go to This direction on windows OS C:\wamp\bin\apache\Apache2.4.4\bin
Then open php.ini file by any editor recommended [sublime] in 514 line just paste this two lines.
;error_reporting = E_ALL error_reporting = E_ALL & ~E_NOTICE

Categories