Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #9188

Re: Undefined variable

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: Undefined variable
Date 2013-04-24 05:55 -0400
Organization A noiseless patient Spider
Message-ID <kl8a06$blh$2@dont-email.me> (permalink)
References <880c3296-ef42-486d-bb06-a69e527e1126@n4g2000yqj.googlegroups.com> <qqien8l21dsam3qh3lelrh52tuugmh5q17@4ax.com> <a3ba4a57-648f-47c5-87b4-3989f43043e7@t5g2000yql.googlegroups.com> <kl88ct$fjn$1@news.albasani.net>

Show all headers | View raw


On 4/24/2013 5:24 AM, The Natural Philosopher wrote:
> On 24/04/13 04:27, Question Boy 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>';
>>>>         }
>>>> but am not sure if the server will break because the variable isn't
>>>> set or if it will still throw an error because of the second,
>>>> original, part of the if statement?  Is this a good way to handle the
>>>> problem, or am I going about this the wrong way and there is a better
>>>> method?
>>>> Thank you for your help.
>>>> QuestionBoy
>>> 1. Yes, it will prevent the error notice.
>>>
>>> 2. You do not need the ==TRUE.   isset($iBookedBy) means the same
>>> isset($iBookedBy)==TRUE.
>>>
>>> 3. Your asking the question suggests that you are trying to write code
>>> and run it directly on a production server rather than testing on a
>>> local server. The webmaster will be happier, and you will be much more
>>> productive, if you set up a local server like WAMP.
>>
>> Thank you for the reply.
>>
>> I was always under the impression that it was always beneficial to
>> explicitly put ==TRUE to avoid any arbitrary interpretations.  I won't
>> waste my time anymore.
> if you are writing code for others of arbitrary moronicity to debug, its
> no bad thing: However the shorthand of if(x) instead of if(x==TRUE) is
> so widely used its unlikely anyone else will bat an eyelid.
>
>>
>> My test server was not reporting any errors.  I will look into which
>> setting has to be changed.
>
> you may be suppressing warnings on it.
>
> my server is full of such errors from the first app I wrote in PHP, but
> they are dwarfed by errors ffrom apache of hackers trying to find
> framework administration files that don't exist, things called
> apple-touch-preconfigured blah blah.
>> Thank you once again.
>
>

Good programmers care about such things.  They indicate problems just 
waiting to crop up.  That's why PHP throws notices when they occur.

Crap programmers make excuses.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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