Welcome to dbForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Is it ok to use error_reporting(0) to get rid of error msg?

 
Goto page 1, 2
   Database Forums (Home) -> PHP RSS
Next:  Triggers  
Author Message
varois83

External


Since: Dec 06, 2004
Posts: 7



(Msg. 1) Posted: Wed Jan 19, 2005 6:57 pm
Post subject: Is it ok to use error_reporting(0) to get rid of error msg?
Archived from groups: comp>lang>php (more info?)

Hi

I am in the process of creating a guestbook for my site, I am a newbie
and used several tutorials and customized them to what I need using the
little knowledge I got.
I get the following error in my code:

Notice: Undefined variable: stars in c:\program
files\easyphp1-7\www\guestbook\add.php on line 60

Which I got to disappear with this locally in my code (PHP.ini still
set to 2047):

<?PHP
error_reporting(0);
?>

Is it ok to do that? Or is it a cheap quick fix? I want to learn PHP
the right way.

Thanks a bunch

Patrick

 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
steve




Joined: Jan 06, 2004
Posts: 655



(Msg. 2) Posted: Wed Jan 19, 2005 11:16 pm
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]

varois83 wrote:
Hi

I am in the process of creating a guestbook for my site, I am a newbie
and used several tutorials and customized them to what I need using the
little knowledge I got.
I get the following error in my code:

Notice: Undefined variable: stars in c:\program
files\easyphp1-7\www\guestbook\add.php on line 60

Which I got to disappear with this locally in my code (PHP.ini still
set to 2047):

<?PHP
error_reporting(0);
?>

Is it ok to do that? Or is it a cheap quick fix? I want to learn PHP
the right way.

Thanks a bunch

Patrick


Patrick, it is recommended that you keep as much error reporting as possible, to make sure you have sufficiently debugged your code.

As far as undefined variables, it is always better to define them. But I have found that I can work with undefined variables as well as long as I am totally consistent about it. So it is the programmers choice IMHO.

there are some great discussions in the comments section of http://ca.php.net/manual/en/function.error-reporting.php well worth reading.

 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
user2424

External


Since: Dec 28, 2004
Posts: 5



(Msg. 3) Posted: Thu Jan 20, 2005 8:45 am
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I noticed that Message-ID: <41ef3143$1_4@alt.athenanews.com> from steve
contained the following:

 >Posted using the <a style='text-decoration: underline;' href="http://www.dbforumz.com" target="_blank">http://www.dbforumz.com</a> interface, at author's request
 >Articles individually checked for conformance to usenet standards

OBTopic: Putting a space before the quoting character is not showing
conformance.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs <a style='text-decoration: underline;' href="http://www.ckdog.co.uk/rfdmaker/" target="_blank">http://www.ckdog.co.uk/rfdmaker/</a><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
varois83

External


Since: Dec 06, 2004
Posts: 7



(Msg. 4) Posted: Thu Jan 20, 2005 11:12 am
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

 > Patrick, it is recommended that you keep as much error reporting as
 > possible, to make sure you have sufficiently debugged your code.
 >
 > As far as undefined variables, it is always better to define them.

Hi

Thanks for the help. Could you tell me how to define a variable in PHP?
Thanks a lot

Patrick<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
Michael Fesser

External


Since: Jul 05, 2004
Posts: 107



(Msg. 5) Posted: Thu Jan 20, 2005 1:40 pm
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

.oO(varois83)

 >I get the following error in my code:
 >
 >Notice: Undefined variable: stars in c:\program
 >files\easyphp1-7\www\guestbook\add.php on line 60
 >
 >Which I got to disappear with this locally in my code (PHP.ini still
 >set to 2047):
 >
 ><?PHP
 >error_reporting(0);
 >?>
 >
 >Is it ok to do that?

No.

 >Or is it a cheap quick fix? I want to learn PHP
 >the right way.

Set error_reporting to E_ALL in the php.ini on your development box and
fix the things PHP complains about. Even if it's just a notice -- it's
bad code and might lead to bugs which are hard to find. For example if
you write $fooBar one time and $foobar another: it's just a little typo,
but a real error because variables are case-sensitive. With E_ALL PHP
will show you a notice.

Some other things:

* Before using a variable for a read-access make sure it is set,
initialize it with an empty value if neccessary:

$aString = '';
$anInt = 0;
$anArray = array();

* Before using user-submitted variables like GET parameters always check
if they exists at all with isset():

if (isset($_GET['foo'])) ...

Micha<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
steve




Joined: Jan 06, 2004
Posts: 655



(Msg. 6) Posted: Thu Jan 20, 2005 1:43 pm
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]

user2424 wrote:
I noticed that Message-ID: <41ef3143$1_4@alt.athenanews.com> from steve
contained the following:

>Posted using the http://www.dbforumz.com interface, at author's request
>Articles individually checked for conformance to usenet standards

OBTopic: Putting a space before the quoting character is not showing
conformance.


Thanks, Geoff. Can you provide a reference on this.
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
steve




Joined: Jan 06, 2004
Posts: 655



(Msg. 7) Posted: Thu Jan 20, 2005 1:58 pm
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]

The point is you can say

if ($a ==1) $b = 2;

here, $b is defined only if the condition is met. If then later on, you call on $b (and the condition was not met) then you get a "undefined" warning from php. So defensive programming would call for:

if ($a ==1) {
$b = 2;
}
else {
$b = '';
}

There are also shorthand ways of doing that. There is obviously more code to write, but the result would be more solid.

On the other hand, you can just accept undefined as a value, and turn the warning reporting off. But the first way is recommended.
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
Andy Hassall

External


Since: Jan 11, 2004
Posts: 465



(Msg. 8) Posted: Thu Jan 20, 2005 3:40 pm
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 20 Jan 2005 13:44:11 -0500, steve <UseLinkToEmail.TakeThisOut@dbForumz.com> wrote:

 >"user2424" wrote:
  > > I noticed that Message-ID: <41ef3143
 >_4@alt.athenanews.com>
  > > from steve
  > > contained the following:
  > >
   > > >Posted using the <a style='text-decoration: underline;' href="http://www.dbforumz.com" target="_blank">http://www.dbforumz.com</a> interface, at
  > > author’s request
   > > >Articles individually checked for conformance to usenet standards
  > >
  > > OBTopic: Putting a space before the quoting character is not
 >showing
  > > conformance.
  > >
 >
 >Thanks, Geoff. Can you provide a reference on this.

There's this draft:

<a style='text-decoration: underline;' href="http://www.karlsruhe.org/rfc/draft-ietf-usefor-useage-00.txt" target="_blank">http://www.karlsruhe.org/rfc/draft-ietf-usefor-useage-00.txt</a>
"
3.2.2.1. Quoting and Attributions

[...]

When a followup agent incorporates the "precursor" as a quotation, it
MUST be distinguished from the surrounding text in some way, and
SHOULD be so dintinguished by prefacing each line of the quoted text
(even if it is empty) with the character ">" (or perhaps with "> " in
the case of a previously unquoted line). This will result in multiple
levels of ">" when quoted content itself contains quoted content, and
it will also facilitate the automatic analysis of articles.
"

Although as the document notes, "It is inappropriate to use Internet-Drafts as
reference material". I don't know off the top of my head any official document
that defines quoting prefixes. ">", no leading space, is certainly the de facto
standard.

--
Andy Hassall / <andy.TakeThisOut@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
steve




Joined: Jan 06, 2004
Posts: 655



(Msg. 9) Posted: Thu Jan 20, 2005 5:22 pm
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]

Thanks, Andy and Geoff. I guess using multiple forward slashes to indent quotes, and then also using spaces to tab is redundant.
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
user2424

External


Since: Dec 28, 2004
Posts: 5



(Msg. 10) Posted: Thu Jan 20, 2005 6:40 pm
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I noticed that Message-ID: <o230v0137ed9mhh67m2qlqtuetmdg8ih41.TakeThisOut@4ax.com>
from Andy Hassall contained the following:

 > Although as the document notes, "It is inappropriate to use Internet-Drafts as
 >reference material". I don't know off the top of my head any official document
 >that defines quoting prefixes. ">", no leading space, is certainly the de facto
 >standard.

Agreed.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs <a style='text-decoration: underline;' href="http://www.ckdog.co.uk/rfdmaker/" target="_blank">http://www.ckdog.co.uk/rfdmaker/</a><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
Chung Leong

External


Since: Dec 06, 2003
Posts: 245



(Msg. 11) Posted: Fri Jan 21, 2005 12:36 am
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"steve" <UseLinkToEmail.RemoveThis@dbForumz.com> wrote in message
news:41ef3143$1_4@alt.athenanews.com...
 > Patrick, it is recommended that you keep as much error reporting as
 > possible, to make sure you have sufficiently debugged your code.

I wouldn't go so far as to imply that keeping error_reporting high can
somehow improve the quality of your code. It doesn't. A PHP script that
doesn't print out error messages is like a C program that successfully
compiles. The computer might not see any problem, but the computer is also
stupid as hell. It has absolutely no clue how your program is supposed to
work. To its assertion that a piece of code is error-free I wouldn't attach
any value.

Error_reporting is a tool for fixing bugs, that's all. Most of the time it's
useful. If you decide not to use it, that's fine too.<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
varois83

External


Since: Dec 06, 2004
Posts: 7



(Msg. 12) Posted: Fri Jan 21, 2005 10:35 am
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

 >
 > The point is you can say
 >
 > if ($a ==1) $b = 2;
 >
 > here, $b is defined only if the condition is met. If then later on,
 > you call on $b (and the condition was not met) then you get a
 > "undefined" warning from php. So defensive programming would call
 > for:
 >
 > if ($a ==1) {
 > $b = 2;
 > }
 > else {
 > $b = '';
 > }

Hi Steve and everybody who was kind to answer.

Thanks to your example Steve I got it now. I am a newbie and some
concepts are sometimes hard to grasp at first.
I haven't fixed my code but I know where the error comes from now.
I have a portion of my guestbook code used for language filter.
When the code processes a bad word it doesn't send the error message as
the variable in charge of replacing the bad word with **** has a value,
but when it compares a good word, a portion of the code isn't processed
so now the variable in charge of assigning the **** which replace the
bad word has no value so the error pops up.
Thanks a bunch to everybody

Patrick<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
steve




Joined: Jan 06, 2004
Posts: 655



(Msg. 13) Posted: Fri Jan 21, 2005 1:59 pm
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]

Patrick, glad to be of help. If you write your own code, it is better to do it right the first time, or accept undefined as a "value" --which is ok too, as long as it is used consistently.

When you get code from others, then oftentimes you don't have a choice. Most3rd party code would have a lot of undefined, and then it is advisable to accept undefined as a value, and go on with it.
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
steve




Joined: Jan 06, 2004
Posts: 655



(Msg. 14) Posted: Fri Jan 21, 2005 2:03 pm
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]

Patrick, glad to be of help. If you write your own code, it is better to do it right the first time, or accept undefined as a "value" --which is ok too, as long as it is used consistently.

When you get code from others, then oftentimes you don't have a choice. Most3rd party code would have a lot of undefined, and then it is advisable to accept undefined as a value, and go on with it.
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
steve




Joined: Jan 06, 2004
Posts: 655



(Msg. 15) Posted: Fri Jan 21, 2005 2:04 pm
Post subject: Re: Is it ok to use error_reporting(0) to get rid of error m [Login to view extended thread Info.]

Patrick, glad to be of help. If you write your own code, it is better to do it right the first time, or accept undefined as a "value" --which is ok too, as long as it is used consistently.

When you get code from others, then oftentimes you don't have a choice. Most3rd party code would have a lot of undefined, and then it is advisable to accept undefined as a value, and go on with it.
 >> Stay informed about: Is it ok to use error_reporting(0) to get rid of error msg? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Error log. - Is there an error log in which PHP reports script related problems ? Peter

Error - I m getting this error while uploading an image through form copy(http://localhost/madame/uploads/alt/medium/zoom.gif) [function.copy]: failed to open stream: HTTP wrapper does not support writeable connections. in..

Parse error - Hi, What's wrong with this line? I'm getting parse errors for it: if ( empty($payment) || !is_numeric($payment) ) {

php3-error - hi all ive got php-4.3.9-3 on my fedora3....tried installing phptimesheet-1.2.4.tar.gz on my system..extracted the folder to document root of apache2..all the files of the timesheet have php3 extensions... php is working fine on my sys but php3 is not..

error while doing 'make' in php-5.2.1 - I am trying to build php-5.2.1 in RedHat Linux 9. I have installed libxml2-2.6.11,mysql-5.0.33,httpd-2.2.4(apache) successfully.When i do 'make' from the php directory,i get the following errors..Not able to proceed further.(./configure went smooth). I...
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada) (change)
Goto page 1, 2
Page 1 of 2

 
You can post new topics in this forum
You can 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



[ Contact us | Terms of Service/Privacy Policy ]