Jump to content

notices


drifter

Recommended Posts

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.