drifter Posted December 23, 2006 Share Posted December 23, 2006 OK I was looking at my code - I have had notices turned off for a while, but when I turn them on I am getting a lot of undefined indexes.Usually they are things like assigning a $_GET['something'] to a variable for use later.So how bad are notices such as these? do they slow things down? should I just turn notices back off and forget it? Would having hundreds of if statements slow it down even more then just leaving it?Thanks Quote Link to comment Share on other sites More sharing options...
trq Posted December 23, 2006 Share Posted December 23, 2006 Notices are signs of poor coding IMO. Its up to you what you want to do with them, but be aware that sometimes Notices can be upgraded to warnings or even errors in newer php versions. Its best to allways develope with error reporting set to E_ALL, this way you wont get in the habbit of not breaking things. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted December 23, 2006 Share Posted December 23, 2006 When you are dealing with user input, $_GET or $_POST variables always check they exist before using them. You can do this using the isset variable:[code=php:0]$myvar = isset($_GET['myvar']) ? $_GET['myvar'] : '';[/code]That way when you run the code PHP will first check that myvar exists before using it, otherwise if you do [code=php:0]$myvar = $_GET['myvar'][/code] PHP will not check the existence of that variable and will expect that variable is already defined, when it can't find it it'll through an undefined notice message (not errors).Notices are not bad, however they should not be ignored. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.