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


Groups > comp.lang.php > #9180 > unrolled thread

Undefined variable

Started byQuestion Boy <question.boy@hotmail.com>
First post2013-04-23 19:16 -0700
Last post2013-04-26 21:30 +0200
Articles 6 on this page of 26 — 11 participants

Back to article view | Back to comp.lang.php


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#9190

FromQuestion Boy <question.boy@hotmail.com>
Date2013-04-24 06:51 -0700
Message-ID<c3ba030a-95f4-455c-9472-6028773556e9@v20g2000yqj.googlegroups.com>
In reply to#9189
On Apr 24, 6:20 am, Christoph Becker <cmbecke...@gmx.de> wrote:
> Question Boy wrote:
> > 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
>
> You should investigate, why $iBookeyBy is undefined.  It is always
> preferable to initialize a variable explicitely before you use it.  This
> is particularly important for PHP due to the dangerous register_globals
> option (which was fortunately removed since PHP 5.4).  If this is
> enabled (what should never be), the code may be vulnerable.  Checking
> for isset($iBookeyBy) won't help in this case.
>
> --
> Christoph M. Becker

Thank you all for all the information!  I have a lot of work ahead of
me to clean thing up.

[toc] | [prev] | [next] | [standalone]


#9196

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2013-04-25 10:10 +0200
Message-ID<ats6ngFiblvU1@mid.uni-berlin.de>
In reply to#9190
Am 24.04.2013 15:51, schrieb Question Boy:
> On Apr 24, 6:20 am, Christoph Becker <cmbecke...@gmx.de> wrote:
>> Question Boy wrote:
>>> 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
>>
>> You should investigate, why $iBookeyBy is undefined.  It is always
>> preferable to initialize a variable explicitely before you use it.  This
>> is particularly important for PHP due to the dangerous register_globals
>> option (which was fortunately removed since PHP 5.4).  If this is
>> enabled (what should never be), the code may be vulnerable.  Checking
>> for isset($iBookeyBy) won't help in this case.
>>
>> --
>> Christoph M. Becker
> 
> Thank you all for all the information!  I have a lot of work ahead of
> me to clean thing up.
> 

I propose a new reading of "PHP Notice: undefined variable...", it goes:

   Hey, you are using a variable that is not defined. I will put a null into it.
   Because I will make it easy for you.
   If you don't care I won't either.
   Maybe you expected the variable to contain something,
   and your app logic will be screwed up.
   It will be _a_lot_of_ work to find the error, but that's your problem.


/Str.

[toc] | [prev] | [next] | [standalone]


#9201

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-04-25 18:23 +0000
Message-ID<klbsbb$2pp$3@dont-email.me>
In reply to#9196
On Thu, 25 Apr 2013 10:10:24 +0200, M. Strobel wrote:

> I propose a new reading of "PHP Notice: undefined variable...", it goes:
> 
>    Hey, you are using a variable that is not defined. I will put a null
..........................................................^^^^

*might*

>    into it.
>    Because I will make it easy for you.
>    If you don't care I won't either.

+ some lines:
     I may put some random value there instead.
     The double I use now might not be the string I use next.
     Or the integer I used last.
     
>    Maybe you expected the variable to contain something,
>    and your app logic will be screwed up.
>    It will be _a_lot_of_ work to find the error, but that's your
>    problem.

(edited to be more complete and future proof)

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#9202

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2013-04-25 22:05 +0200
Message-ID<attgkqFrjncU1@mid.uni-berlin.de>
In reply to#9201
Am 25.04.2013 20:23, schrieb Denis McMahon:
> On Thu, 25 Apr 2013 10:10:24 +0200, M. Strobel wrote:
> 
>> I propose a new reading of "PHP Notice: undefined variable...", it goes:
>>
>>    Hey, you are using a variable that is not defined. I will put a null
> ..........................................................^^^^
> 
> *might*
> 
>>    into it.
>>    Because I will make it easy for you.
>>    If you don't care I won't either.
> 
> + some lines:
>      I may put some random value there instead.
>      The double I use now might not be the string I use next.
>      Or the integer I used last.
>      
>>    Maybe you expected the variable to contain something,
>>    and your app logic will be screwed up.
>>    It will be _a_lot_of_ work to find the error, but that's your
>>    problem.
> 
> (edited to be more complete and future proof)
> 

ah, a new community project :-)

I thought (and read) the variables were defined after being accessed, but they are
not. Very strange decisions of the PHP makers. Console log:

> echo $a, PHP_EOL;
PHP Notice:  Undefined variable: a in /usr/local/bin/myreadline.php(42) : eval()'d
code on line 1

> var_dump($a);
PHP Notice:  Undefined variable: a in /usr/local/bin/myreadline.php(42) : eval()'d
code on line 1
NULL
> if ($a==0.0) echo "yes\n";
PHP Notice:  Undefined variable: a in /usr/local/bin/myreadline.php(42) : eval()'d
code on line 1
yes
> var_dump($a);
PHP Notice:  Undefined variable: a in /usr/local/bin/myreadline.php(42) : eval()'d
code on line 1
NULL

/Str.

[toc] | [prev] | [next] | [standalone]


#9203

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-04-26 03:27 +0000
Message-ID<klcs7o$2pp$6@dont-email.me>
In reply to#9202
On Thu, 25 Apr 2013 22:05:46 +0200, M. Strobel wrote:

> Am 25.04.2013 20:23, schrieb Denis McMahon:
>> On Thu, 25 Apr 2013 10:10:24 +0200, M. Strobel wrote:
>> 
>>> I propose a new reading of "PHP Notice: undefined variable...", it
>>> goes:
>>>
>>>    Hey, you are using a variable that is not defined. I will put a
>>>    null
>> ..........................................................^^^^
>> 
>> *might*
>> 
>>>    into it.
>>>    Because I will make it easy for you.
>>>    If you don't care I won't either.
>> 
>> + some lines:
>>      I may put some random value there instead.
>>      The double I use now might not be the string I use next.
>>      Or the integer I used last.
>>      
>>>    Maybe you expected the variable to contain something,
>>>    and your app logic will be screwed up.
>>>    It will be _a_lot_of_ work to find the error, but that's your
>>>    problem.
>> 
>> (edited to be more complete and future proof)
>> 
>> 
> ah, a new community project :-)
> 
> I thought (and read) the variables were defined after being accessed,
> but they are not. Very strange decisions of the PHP makers. Console log:

Yes, but that always might change in the next update ;)

I did wonder about:

"The array of doubles I'm using now might not be the class of kitten 
hugging monkeys I'll use next week or the tuples of solar hydrogen I used 
yesterday."

but that seemed perhaps a little too complex for some of the readers 
here. :)

(although the kitten hugging monkeys may be more intelligent than some of 
those readers too ... and come to that, so might the tuples of solar 
hydrogen)

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#9210

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-04-26 21:30 +0200
Message-ID<2636064.ipUkTV1W5V@PointedEars.de>
In reply to#9203
Denis McMahon wrote:

> On Thu, 25 Apr 2013 22:05:46 +0200, M. Strobel wrote:
>> Am 25.04.2013 20:23, schrieb Denis McMahon:
>>> On Thu, 25 Apr 2013 10:10:24 +0200, M. Strobel wrote:
>>>> I propose a new reading of "PHP Notice: undefined variable...", it
>>>> goes:
>>>>
>>>>    Hey, you are using a variable that is not defined. I will put a
>>>>    null
>>> ..........................................................^^^^
>>> 
>>> *might*
>>> 
>>>>    into it.
>>>>    Because I will make it easy for you.
>>>>    If you don't care I won't either.
>>> 
>>> + some lines:
>>>      I may put some random value there instead.
>>>      The double I use now might not be the string I use next.
>>>      Or the integer I used last.
>>> […]     
> […]
> 
> I did wonder about:
> 
> "The array of doubles I'm using now might not be the class of kitten
> hugging monkeys I'll use next week or the tuples of solar hydrogen I used
> yesterday."
> 
> but that seemed perhaps a little too complex for some of the readers
> here. :)
> 
> (although the kitten hugging monkeys may be more intelligent than some of
> those readers too ... and come to that, so might the tuples of solar
> hydrogen)

However, the non-trolling reader will observe that the evaluation value of a 
reference to an undefined variable actually *is* NULL, and that type 
juggling as it occurs e.g. with the “==” operator or a type-converting test 
(as opposed to with “===”) is *well-defined* (albeit perhaps unintuitive to 
some), in PHP (and other dynamically typed programming languages).

It is simply false that a replacement value will be chosen randomly.

<http://www.php.net/manual/en/language.variables.basics.php>
<http://www.php.net/manual/en/language.types.type-juggling.php>


PointedEars
-- 
Sometimes, what you learn is wrong. If those wrong ideas are close to the 
root of the knowledge tree you build on a particular subject, pruning the 
bad branches can sometimes cause the whole tree to collapse.
  -- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.php


csiph-web