Page 1 of 1
Help getting ride of Notices..
Posted: Fri Feb 03, 2006 8:51 am
by waskelton4
So,
I went in to php.ini and turned error report to E_ALL... and the notices started flying..
many of them i'm able to fix but a few i'm having problems with.
for instance..
sometimes something like
will throw:
Notice: Undefined index: btnSubmit in c:\xxx\xxx\userlist.php on line 23
do i have to define all of my posted variables in all of my pages that I am posting to?
ws
Posted: Fri Feb 03, 2006 9:18 am
by Jenk
Don't have to define them, before your code tries to use them you can check that they have been defined first with isset(), e.g:
Code: Select all
<?php
if (isset($_POST['btnSubmit'])) {
//do something with $_POST['btnSubmit']
}
?>
Posted: Fri Feb 03, 2006 9:30 am
by waskelton4
Thanks!
I got some of them to go away..
next question..
How much will it benefit me to try and get rid of all the notices?
It sure is easier to just not display them..
ws
Posted: Fri Feb 03, 2006 9:32 am
by Jenk
It's bad practice to sweep exceptions under the carpet like that..
Setting error_reporting(0) and/or display_errors(0) does not stop the errors occuring, it only stops them being reported. They still need to be caught and handled accordingly.
Though the difference in performance is negligible at best.
Posted: Fri Feb 03, 2006 9:38 am
by waskelton4
consider my hand slapped
I'm still displaying all my errors and warnings.. it is just the notices that give me trouble...
I guess I'll leave all my errors displaying for the time being and see how i handle it.
ws
Posted: Fri Feb 03, 2006 9:46 am
by Jenk
Leaving them set to display should only occur during development, then when you are satisfied that your application does not produce any of the php E_ errors, it is best advised to set display_errors(0) and set error_reporting(0) so that in the chance of someone wanting to crack your site, life won't be easy for them due to the sensitive info these errors can produce. (directory stucture being the main one)
Posted: Fri Feb 03, 2006 9:48 am
by feyd
the difference can be significant if you would normally generate many (read hundreds) of notices. All the errors still fire, and php has to handle them. It's a fairly linear increase in processing requirements overall. I've personally seen ten fold speed improvements when I accidentally had a script that generated about 10000 notices (lots and lots of calls to the same area of code thankfully)
Posted: Fri Feb 03, 2006 9:49 am
by waskelton4
That is currently how my test and production environments are setup..
I have a seperate production server that doesn't display any errors at all while the test server does.
Thanks for the help!
Will