Handling notices

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Handling notices

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Handling notices

Post 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; ?>">
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Handling notices

Post 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
Post Reply