I don't like being warned

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
marlin
-


Joined: 01 Sep 2006
Posts: 11

PostPosted: Sat Jul 02, 2022 8:23 pm    Post subject: I don't like being warned Reply with quote

I copied a bunch of php scripts that have been working fine to a new computer. In all of the scripts I now get multiple warning messages complaining about undefined variables. They only serve to make the output ugly. The scripts have long been debugged; and still work properly, except for the messages..

I ran phpinfo.php which showed the error_reporting code to be 32765. I also inspected the php.ini file which included the directive

error_reporting = E_ALL ^ E_WARNING.

Finally, I inserted the command

echo 'error_reporting: '. error_reporting( ) ;

as the first line in one of my scripts; and the result was 32765. Now the code for all errors is 32767 and 2 for warnings. Thus 32767 - 2 = 32765.

So why are the warnings appearing?

I'm running the scripts on a windows laptop with the Abyss Web Server,
Back to top View user's profile Send private message Visit poster's website
admin
Site Admin


Joined: 03 Mar 2002
Posts: 1295

PostPosted: Sat Jul 09, 2022 9:01 pm    Post subject: Re: I don't like being warned Reply with quote

marlin,

PHP has several flavors of warnings. E_WARNING is only for a single kind of them.

You could be getting warnings about deprecation or other issues and these are not usually covered by E_WARNING.

Try setting in php.ini:

Code:
error_reporting = E_ALL & ~E_WARNING & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

_________________
Follow @abyssws on Twitter
Subscribe to our newsletter
_________________
Forum Administrator
Aprelium - https://aprelium.com
Back to top View user's profile Send private message
marlin
-


Joined: 01 Sep 2006
Posts: 11

PostPosted: Tue Jul 12, 2022 12:57 am    Post subject: Reply with quote

As I mention, the warnings are about undefined variables. It dawned on me that that is a good thing on my laptop, because that is where I debug programs and it's good to have undefined variables flagged because, although many are by design, some are typos I would want to know about.

The web hosting service where I upload scripts doesn't show warnings, which is just what I want.

That still begs the question of how to squelch warnings on my local machine.
Back to top View user's profile Send private message Visit poster's website
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Wed Jul 13, 2022 12:31 pm    Post subject: Reply with quote

marlin wrote:
That still begs the question of how to squelch warnings on my local machine.


You can find examples here: https://www.php.net/manual/en/function.error-reporting.php
You can set the error reporting level right in your script, and just change that level when you send to production.

You can also set it in your php.ini file, as Aprelium guided you:
admin wrote:
error_reporting = E_ALL & ~E_WARNING & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

This will turn off warnings, notices, deprecation notices, etc.

You can also change your php.ini value for display_errors. Set it to off and you should be a lot happier.
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group