Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #9204
| From | Chuck Anderson <cycletourist@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Undefined variable |
| Date | 2013-04-25 23:59 -0600 |
| Organization | cycletourist.com |
| Message-ID | <kld516$cfh$1@dont-email.me> (permalink) |
| References | (3 earlier) <1bf2b927-60fd-4abe-8a09-331aa601e494@o6g2000yqo.googlegroups.com> <kl9dlq$huj$1@dont-email.me> <kla3tv$ksq$1@dont-email.me> <klakci$eld$1@dont-email.me> <klasej$j5q$1@dont-email.me> |
Jerry Stuckle wrote:
> On 4/25/2013 3:03 AM, Chuck Anderson wrote:
>> Jerry Stuckle wrote:
>>> On 4/24/2013 4:02 PM, Chuck Anderson wrote:
>>>> Question Boy wrote:
>>>>> On Apr 23, 11:27 pm, Question Boy <question....@hotmail.com> wrote:
>>>>>> On Apr 23, 11:08 pm, Richard Yates <rich...@yatesguitar.com> wrote:
>>>>>>
>>>>>>> On Tue, 23 Apr 2013 19:16:54 -0700 (PDT), Question Boy
>>>>>>> <question....@hotmail.com> wrote:
>>>>>>>> I have an simple MySQL/PHP app and it appears to be functional
>>>>>>>> but the
>>>>>>>> webmaster has informed me that it is throwing lots of errors.
>>>>>>>> So he
>>>>>>>> showed me the log file and I am trying to remedy the issues, but
>>>>>>>> have
>>>>>>>> a question.
>>>>>>>> For instance, I have a block of code, such as:
>>>>>>>> if ($iBookedBy=="Other") {
>>>>>>>> echo '<option selected value="Other">Other</option>';
>>>>>>>> } else {
>>>>>>>> echo '<option value="Other">Other</option>';
>>>>>>>> }
>>>>>>>> which the log file reports as:
>>>>>>>> PHP Notice: Undefined variable: iBookedBy
>>>>>>>> Now I thought of trying:
>>>>>>>> if (isset($iBookedBy)==TRUE && $iBookedBy=="Other") {
>>>>>>>> echo '<option selected value="Other">Other</option>';
>>>>>>>> } else {
>>>>>>>> echo '<option value="Other">Other</option>';
>>>>>>>> }
>>>>
>>>> My guess is that you are running Php < 5.3 on your development
>>>> machine,
>>>> and the production server is running 5.3+. That is why your test
>>>> system
>>>> does not produce the errors and the production machine does. When I
>>>> upgraded to Php 5.3 some of my older scripts threw lots of these
>>>> errors.
>>>> I found that the best way to correct them was to create a section near
>>>> the top of the script where I set all variables needed by the
>>>> script to
>>>> their default values (usually either '', or 0). Add a comment and
>>>> you're
>>>> also creating useful documentation.
>>>>
>>>
[ ... snip ... ]
>>> Setting variables to their default values is a good idea - but only if
>>> their equivalent isn't defined in $_POST, $_SESSION, etc.
>>
>> That is not a problem for me. I do not initialize "REQUEST" variables
>> (POST, GET, COOKIE, SESSION) - and I never have register_globals
>> enabled, so setting a local variable to a default value never conflicts
>> with the super global REQUEST variables.
>>
>
> I don't use $_REQUEST at all. I like to know where my data are coming
> from.
Just a point of clarification. I was using the word REQUEST as a
shortcut to indicate POST, GET, and COOKIE.
>> a prologue) and then I go through my REQUEST ($_POST, $_GET) variables
>> and set a corresponding local variable to it's value which I then use in
>> my script. I almost never use REQUEST variables directly within my
>> script. This also forces me to remember to cleanse any user input.
>>
> I set local variables to default values near the top of the script (like
>
> I learned this way in C (actually way back in Fortran II).
It was C prologues for me - and a proprietary language I used
extensively at Bell Labs.
[ .... snip ... ]
>>> Again, you are only hiding the problems, not fixing them!
>>
>> I know. And again, I also said as much.
>>
>
> Yes, but as I said before - too many people read such updates as
> "fixes", even though you said they aren't.
>
Poor Buggers ;-)
--
*****************************
Chuck Anderson • Boulder, CO
http://cycletourist.com
Turn Off, Tune Out, Drop In
*****************************
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Undefined variable Question Boy <question.boy@hotmail.com> - 2013-04-23 19:16 -0700
Re: Undefined variable Question Boy <question.boy@hotmail.com> - 2013-04-23 20:06 -0700
Re: Undefined variable Richard Yates <richard@yatesguitar.com> - 2013-04-23 20:08 -0700
Re: Undefined variable Question Boy <question.boy@hotmail.com> - 2013-04-23 20:27 -0700
Re: Undefined variable Question Boy <question.boy@hotmail.com> - 2013-04-23 20:49 -0700
Re: Undefined variable David Robley <me@home.invalid> - 2013-04-24 17:34 +0930
Re: Undefined variable Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-24 05:53 -0400
Re: Undefined variable Chuck Anderson <cycletourist@invalid.invalid> - 2013-04-24 14:02 -0600
Re: Undefined variable Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-24 22:23 -0400
Re: Undefined variable Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-24 22:24 -0400
Re: Undefined variable Tim Streater <timstreater@greenbee.net> - 2013-04-25 08:36 +0100
Re: Undefined variable Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-25 05:13 -0400
Re: Undefined variable Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-25 14:04 +0200
Re: Undefined variable The Natural Philosopher <tnp@invalid.invalid> - 2013-04-25 13:12 +0100
Re: Undefined variable Chuck Anderson <cycletourist@invalid.invalid> - 2013-04-25 01:03 -0600
Re: Undefined variable Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-25 05:22 -0400
Re: Undefined variable Chuck Anderson <cycletourist@invalid.invalid> - 2013-04-25 23:59 -0600
Re: Undefined variable The Natural Philosopher <tnp@invalid.invalid> - 2013-04-24 10:24 +0100
Re: Undefined variable Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-24 05:55 -0400
Re: Undefined variable Christoph Becker <cmbecker69@gmx.de> - 2013-04-24 12:20 +0200
Re: Undefined variable Question Boy <question.boy@hotmail.com> - 2013-04-24 06:51 -0700
Re: Undefined variable "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-04-25 10:10 +0200
Re: Undefined variable Denis McMahon <denismfmcmahon@gmail.com> - 2013-04-25 18:23 +0000
Re: Undefined variable "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-04-25 22:05 +0200
Re: Undefined variable Denis McMahon <denismfmcmahon@gmail.com> - 2013-04-26 03:27 +0000
Re: Undefined variable Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-26 21:30 +0200
csiph-web