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?
Handling notices
Moderator: General Moderators
Re: Handling notices
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
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