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
https://forums.phpfreaks.com/topic/31635-notices/
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
https://forums.phpfreaks.com/topic/31635-notices/#findComment-146640
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
https://forums.phpfreaks.com/topic/31635-notices/#findComment-146911
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.