Re: Warning: Undefined variable
| From: | Erik Price | Date: | Tue, 02 Apr 2002 21:20:15 +0000 |
| Subject: | Re: Warning: Undefined variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-91220@lists.php.net to get a copy of this message | ||
On Tuesday, April 2, 2002, at 03:27 PM, Philip Olson wrote:
If you're distributing code in cyberspace it's a good idea to make it error free too, E_NOTICE or otherwise.I got back quite a few responses on this list on the subject of having variables that are not defined before they are used. That's interesting -- it's nice to know that I can take shortcuts and conjure them up on the fly, but I didn't realize that it was good practice to declare the variable before you actually use it in a script. (I never studied programming in any formal sense, as anyone who has seen my source code can attest :). Sometimes I create variables dynamically, such that I could never declare/initialize them in any realistic sense -- for instance, I might have a while loop that executes a number of times equal to the number of rows pulled from a database query. And in this while loop, I might generate a new variable (assigning it a name like $variable$i, using the old $i++ trick to give it a unique numeric suffix). If I use this trick, does this doom me to never having fully-error-free code? Or is there something that I'm not getting here... The short of it is that, as a novice programmer, I'd like to make sure I'm writing the most legitimate code that I can. Thanks for any input on this thread, past or future. Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.com