Page 1 of 1

Handling notices

Posted: Mon Apr 06, 2009 8:48 pm
by Mr Tech
I'm creating a new script and have enabled notices for debugging purposes. What is the best way to handle Notices? (e.g. Notice: Undefined property: whatever in /path/file.php on line 79)

Is there a better way to display data on a page without causing those notices than something like this:

<input name="first_name" value="<?php if (isset($first_name)) { echo $first_name; } ?>">

What is the common practice?

Re: Handling notices

Posted: Mon Apr 06, 2009 9:16 pm
by requinix
Not sure there really is a "common practice" (programming is part art, part science), but I tend to handle that kind of work earlier on in the script.

Code: Select all

<?php
 
$first_name = ifset($_POST, "first_name", "");
// function that basically does
//return isset($_POST["first_name"]) ? $_POST["first_name"] : "";
 
// ...
?>
<input type="text" name="first_name" value="<?php echo $first_name; ?>">

Re: Handling notices

Posted: Mon Apr 06, 2009 11:19 pm
by josh
You should code in such a way the notices are not generated. They are very helpful in catching issues and if you code in a way that triggers them everywhere you loose their value and get yourself into the very dilema you're in now