Re: Undefined variable [message #181259 is a reply to message #181253] |
Fri, 26 April 2013 05:59 |
Chuck Anderson
Messages: 63 Registered: September 2010
Karma:
|
Member |
|
|
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
*****************************
|
|
|