SLSCoder Posted March 23, 2022 Share Posted March 23, 2022 I've been through this a hundred times. I cannot make php display errors consistently. My php.ini file has this: error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT display_errors = On display_startup_errors = On log_errors = On ignore_repeated_errors = Off ignore_repeated_source = Off report_memleaks = On Nothing exists below these params that would change them. I have a file https://dev.aecperformance.com/php_info.php which shows my php info. When I pull that up I see: Loaded Configuration File /etc/php/8.1/apache2/php.ini I don't understand why this is. It used to be in /etc/php/8.1/fpm php8.1-fpm is installed and is active. Whether or not php is actually using it I can't say. It should be using fpm. Nevertheless, I have uploaded the php.ini file to both: /etc/php/8.1/apache2/php.ini and to /etc/php/8.1/fpm/php.ini I've rebooted the server since making the changes to make sure that php is reloaded. On my web page I have: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); STILL when I try to load the page I get: This page isn’t workinghttps://dev.aecperformance.com/test.php How can I make PHP display errors and suppress warnings? Quote Link to comment https://forums.phpfreaks.com/topic/314615-how-can-i-make-php-display-errors-and-hide-warnings/ Share on other sites More sharing options...
requinix Posted March 23, 2022 Share Posted March 23, 2022 Quote Warning: Undefined variable $oDaQB in /var/www/dev.aecperformance.com/DataAccess/daRptQuestionInq.php on line 4 Testing 1, 2, 3 Looks fine to me. Is the problem your browser? Quote Link to comment https://forums.phpfreaks.com/topic/314615-how-can-i-make-php-display-errors-and-hide-warnings/#findComment-1594491 Share on other sites More sharing options...
SLSCoder Posted March 23, 2022 Author Share Posted March 23, 2022 Yea, sorry. I'm working on it. It turns out that it seems to be doing it on compile time errors. What caused it to return This page isn't working was a missing semi-colon. Quote Link to comment https://forums.phpfreaks.com/topic/314615-how-can-i-make-php-display-errors-and-hide-warnings/#findComment-1594492 Share on other sites More sharing options...
SLSCoder Posted March 23, 2022 Author Share Posted March 23, 2022 This code works $sErr = "Hello World"; echo $sErr . "<br>"; This code makes the page display: This page isn’t working $sErr = "Hello World" echo $sErr . "<br>"; Why is it doing that and how can I make it show me the error? Quote Link to comment https://forums.phpfreaks.com/topic/314615-how-can-i-make-php-display-errors-and-hide-warnings/#findComment-1594494 Share on other sites More sharing options...
Barand Posted March 23, 2022 Share Posted March 23, 2022 56 minutes ago, SLSCoder said: On my web page I have: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); If you have the settings that you want in the ini file, why override them with E_ALL in your webpage? Quote Link to comment https://forums.phpfreaks.com/topic/314615-how-can-i-make-php-display-errors-and-hide-warnings/#findComment-1594495 Share on other sites More sharing options...
gizmola Posted March 23, 2022 Share Posted March 23, 2022 Just based on the title of this thread: error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT Do you understand what the & and ~ do here, in terms of bitwise operations? Hopefully you understand that this starts with everything, and suppresses notices, deprecation messages and "strict" checking. Warnings are covered by E_WARNING. So if you truly want to suppress warnings, then you should have: error_reporting = E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT Changing settings in a script doesn't always work, depending on the type of error in your code, and to Barand's point, doesn't make sense in most cases, when you can just make settings what you want them to be in the .ini. Quote Link to comment https://forums.phpfreaks.com/topic/314615-how-can-i-make-php-display-errors-and-hide-warnings/#findComment-1594496 Share on other sites More sharing options...
Barand Posted March 23, 2022 Share Posted March 23, 2022 I would recommend that, while developing, you should use E_ALL with no suppression of the other levels. Quote Link to comment https://forums.phpfreaks.com/topic/314615-how-can-i-make-php-display-errors-and-hide-warnings/#findComment-1594500 Share on other sites More sharing options...
gizmola Posted March 23, 2022 Share Posted March 23, 2022 8 minutes ago, Barand said: I would recommend that, while developing, you should use E_ALL with no suppression of the other levels. I agree. There might come a time when you have problems you can't fix with a reasonable amount of effort, particularly if those problems are in libraries where you can't upgrade, but for anything new, you should just fix the issues, or as many as you can. Turning all the messaging off means you won't even know about many of the things that should be addressed. Quote Link to comment https://forums.phpfreaks.com/topic/314615-how-can-i-make-php-display-errors-and-hide-warnings/#findComment-1594501 Share on other sites More sharing options...
SLSCoder Posted March 24, 2022 Author Share Posted March 24, 2022 I added the code in the page because it still would not display the errors. I wasn't confident that I had the 'right' php.ini file even though I did edit the one shown in php_info.php. Normally, that code wouldn't be there. I'm aware that & ~E_NOTICE turns off notices. My problem was that even if I have php.ini set as: error_reporting = E_ALL the page still wouldn't show the parse error. The error was caused by a missing semi colon and yesterday the page returned: This page isn’t working Today the error displays as it should. I've removed the error display code on the page and it still works fine. I *swear* I didn't change anything. Yesterday when I quit, it didn't work. Today, it works just fine. ?#)!@#$??? It's all good now. You guys are a lot of help. We appreciate you. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/314615-how-can-i-make-php-display-errors-and-hide-warnings/#findComment-1594508 Share on other sites More sharing options...
kicken Posted March 24, 2022 Share Posted March 24, 2022 (edited) On 3/23/2022 at 2:53 PM, SLSCoder said: Whether or not php is actually using it I can't say. It should be using fpm. It's not, for what it's worth. You can tell by looking at the Server API: line in the phpinfo() output. Yours says: Server API Apache 2.0 Handler If you were using FPM, it would says Server API FPM/FastCGI So if you want to use FPM you need to adjust your configuration for apache to do so. If you don't really care, then just make sure you edit appropriate php configuration file. On 3/23/2022 at 2:53 PM, SLSCoder said: On my web page I have: Having code in the page won't help with issues that prevent the page from running in the first place such as your syntax errors. For that the settings must be configured in the php.ini file. After making changes in the php.ini file, you need to reload the configuration by reloading/restarting the apache service. Edited March 24, 2022 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/314615-how-can-i-make-php-display-errors-and-hide-warnings/#findComment-1594551 Share on other sites More sharing options...
gizmola Posted March 25, 2022 Share Posted March 25, 2022 Most decent editors show you syntax errors as you edit. What are you using? You can also use your command line php with -l for linting. php -l /path/to/script.php Quote Link to comment https://forums.phpfreaks.com/topic/314615-how-can-i-make-php-display-errors-and-hide-warnings/#findComment-1594556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.