Help getting ride of Notices..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Help getting ride of Notices..

Post 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

Code: Select all

$_POST['btnSubmit']
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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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']
} 

?>
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Post 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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Post 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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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)
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Post 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
Post Reply