473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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

Jul 17 '05 #1
11 10498
"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...-reporting.php well worth
reading.

--
Posted using the http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/PHP-error_re...ict189490.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=640399
Jul 17 '05 #2
I noticed that Message-ID: <41**********@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.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
.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
Jul 17 '05 #4
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

Jul 17 '05 #5
"user2424" wrote:
I noticed that Message-ID: <41ef3143 _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.
Jul 17 '05 #6
"varois83" wrote:
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


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.

--
Posted using the http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/PHP-error_re...ict189490.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=641236
Jul 17 '05 #7
On 20 Jan 2005 13:44:11 -0500, steve <Us************@dbForumz.com> wrote:
"user2424" wrote:
I noticed that Message-ID: <41ef3143

_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.


There's this draft:

http://www.karlsruhe.org/rfc/draft-i...-useage-00.txt
"
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 / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #8
"Andy Hassall" wrote:
On 20 Jan 2005 13:44:11 -0500, steve
<Us************@dbForumz.com> wrote:
"user2424" wrote:

&nbsp;> > I noticed that Message-ID: &lt;41ef3143
_4@alt.athenanews.com&gt;

&nbsp;> > from steve
&nbsp;> > contained the following:
&nbsp;> >
&nbsp;&nbsp;> > >Posted using the http://www.dbforumz.com
interface, at
&nbsp;> > author’s request
&nbsp;&nbsp;> > >Articles individually checked for conformance
to usenet standards
&nbsp;> >
&nbsp;> > OBTopic: Putting a space before the quoting
character is not
showing

&nbsp;> > conformance.
&nbsp;> >

Thanks, Geoff. Can you provide a reference on this.


There's this draft:

http://www.karlsruhe.org/rfc/draft-i...-useage-00.txt
"
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 "&gt;" (or perhaps
with "&gt; " in
the case of a previously unquoted line). This will result
in multiple
levels of "&gt;" 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 / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage
analysis tool


Thanks, Andy and Geoff. I guess using multiple forward slashes to
indent quotes, and then also using spaces to tab is redundant.
Jul 17 '05 #9
I noticed that Message-ID: <o2********************************@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 http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #10
"steve" <Us************@dbForumz.com> wrote in message
news:41**********@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.
Jul 17 '05 #11

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

Jul 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: matty | last post by:
Just a couple of quick comments: In some of the CSS/DOM mailing lists I'm on, people generally refuse to help unless the HTML and CSS will validate. You can check these at...
6
by: Tim Tyler | last post by:
I've been experimenting with using: error_reporting (E_ALL); However, lines like this report problems when the variable is missing: $open = $_GET; Is there some way to do that with error...
1
by: lawrence | last post by:
This line: if (file_exists($fileName)) { is (on some web servers) giving me this kind of error: Warning: SAFE MODE Restriction in effect. The script whose uid is 1022 is not allowed to...
1
by: Pedro Fonseca | last post by:
Greetings everyone! I'm porting my applications to PHP5 and I've stumbled on yet another problem. I'll try to simplify things a bit. I have a main script that is being executed (index.php, PHP5...
9
by: comp.lang.php | last post by:
I am having problems tracing errors in my code using PHP 4.3.9 on Linux RHEL 4 with Apache 2.0.54 On occasions I see no errors, no parse, no fatal, no warnings, no notices.. and no code either!...
2
by: comp.lang.php | last post by:
I am trying to debug an error found somewhere within my suite of scripts. Nothing shows up when there's an error, it just simply dies. I tried using error_reporting(E_ALL); to no avail. I tried...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
2
by: mrbog | last post by:
Here's my code: <?php error_reporting(E_ALL); ini_set("display_startup_errors","1"); ini_set("display_errors","1"); wefw wefwef=wefwe
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.