Error_reporting not affecting the error level - php

I'm trying to hide a deprecated warning on a site and so I've added error_reporting(E_ALL ^ E_DEPRECATED); but it's not having any effect. I've got the following test running:
error_reporting(E_ALL ^ E_DEPRECATED);
var_dump(E_ALL ^ E_DEPRECATED, error_reporting());
And the var_dump is outputting int(24575) int(32759), as you can see error_reporting isn't being set. I've also tried error_reporting(24575); just in case, and that didn't do anything either.
I've checked ini_get('error_reporting'); and that also returns 32759. Using ini_set('error_reporting', E_ALL ^ E_DEPRECATED); also doesn't change the error level.
A little more info about the server: It's a VPS configured through WHM used for development purposes. This site is running on PHP 5.6 FPM. The server was upgraded this morning to Easy Apache 4 to enable PHP 7, though 5.6 was left as an option for older sites such as this one.
Does anyone know why error_reporting isn't changing the error level? I've tried googling this but all I get are questions on how to get errors to show or hide, nothing on why error_reporting isn't changing the error level.

Turns out it was PHP-FPM, apparently it doesn't allow you to modify the configuration variables directly. The only place it can be changed is in the config file for PHP-FPM. I've disabled FPM for this site and it's working fine now.

Related

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

Configure PHP on IIS with FastCGI to show warnings but continue executiuon

I am using PHP (7.3.7) Non-ThreadSafe on IIS (windows) as FastCGI.
PHP installation is fresh and just php.ini-development renamed to php.ini thus error_reporting is set to E_ALL
running following script
<?php
echo "some text\n" ;
echo $aaaaaaa;
echo "another text\n" ;
?>
will generate output
PHP Notice: Undefined variable: aaaaaaa in ****\article.php on line 3
Note that first and 3rd lines are missing from output.
Using same installation of php, on apache (2.4.39) and nginx (1.17.2) (also on windows system) shows following output
some text
PHP Notice: Undefined variable: aaaaaaa in ****\article.php on line 3
another text
Is there an specific configuration that I need to change so PHP show same output as apache, nginx in IIS too?
or in other words, how can I configure my setup to show warning and notices and also the output of script.
I tried same script with PHP (7.1.30, 7.2.11, 5.2.10.10) and same issue still persists on IIS but not on apache or nginx.
Edit
I know that if I set error_reporting is set to E_ALL, all errors, warning and notices are shown and when I change it to E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED notices and warnings are disabled and won't show.
I also know that $aaaaaaa is not defined and it being there is for illustration of the issue.
Edit 2
It seems this has to do with configuration of fast-cgi on IIS. On same machine with same php installation and configuration using apache and nginx I can see exactly what Phil and sancoLgates shown in their links. I am editing my question to reflect the issue
In your code variable $aaaaaaa is not defined so define it first.
To check error add this code
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
// and then add your code below
?>

Can't seem to turn off deprecated errors in php

Im on a development server using a version of php that doesn't support mysql_connect() our production server does. I have tried: error_reporting = E_ALL ^ E_DEPRECATED but it doesn't work. After restarting Apache I still the deprecated error message.
I have access to the ini file I should not need php functions to change the error reporting. this is also for wordpress.
error_reporting() is a function. Try: error_reporting(E_ALL ^ E_DEPRECATED ^ E_USER_DEPRECATED);. Or ini_set("error_reporting", E_ALL & ~E_DEPRECATED);. Then test the settings with echo ini_get("error_reporting");. Minimal PHP version must be 5.3.0 for that.
Try replacing your mysql_connect() with mysqli_connect()
Are you sure that you've modified the correct php.ini? Often there are several included with an install. Is this happening on your local development machine, or on a live server? The best way to make sure you've modified the right php.ini is to run a phpinfo file.
Create a new file, name it phpinfo.php and write:
<?php echo phpinfo(); ?>
Run this script in your browser and go down to the line that says "Loaded Configuration File"
This used to cause me headaches when using a WAMP install.
WordPress sets the error_reporting to E_ALL in its config files, thus overriding whatever you've set in php.ini. I beleieve setting error_reporting(E_ALL ^ E_DEPRECATED) in wp-config.php clears it up. See Turn off deprecated errors php 5.3 for various and sundry variations on that setting.
setting: define('WP_DEBUG', false); to false fixed the issue.

PHP errors make page inaccessible

Every time I have an error within my code and try to run it, the page becomes inaccessible. This is clearly very frustrating as it's hard debugging code with no feedback.
Relevant information from cPanel:
Apache version 2.2.22
PHP version 5.3.14
MySQL version 5.1.68-cll
Architecture x86_64
Operating system linux
If more information is required then please ask, I'm sorry I cannot provide any more information but frankly I am stumped.
Thanks.
Enable error reporting to see what error PHP had, if it had one.
There are several places you can look, firstly try checking your Apache error log. In many cases this is located in /var/log/apache2/error.log . Another way to debug a page like this is to enable error logging.
The simplest way of doing this being adding these lines to your php file:
ini_set('display_errors',1);
error_reporting(E_ALL);
In addition to this, you can also clean up the errors formatting by adding:
ini_set('html_errors', 'On');
In addition to this method of enabling error reporting, you may also enable them from you configuration file by adding the following line:
error_reporting = E_ALL
You need to update your php.ini to display errors. There are a couple settings.
Search your php.ini for display_errors and error_reporting. The file is usually commented very well on the options for error reporting, but error_reporting = E_ALL is a typical setting. Sometimes people want to suppress notices and set error_reporting to E_ALL & ~E_NOTICE.
display_errors = On is the config to print the errors to the screen.
After changing your php.ini, Apache usually needs to be restarted. I'm not sure how much control you have over your server, so if you can't restart Apache but you have a php.ini available, your host probably has it configured so you don't need to restart.

How to enable notices on my development server

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

Categories