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


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

missing variable

Started bybill <nobody@spamcop.net>
First post2011-10-29 15:42 -0400
Last post2011-10-31 06:30 -0400
Articles 7 — 4 participants

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


Contents

  missing variable bill <nobody@spamcop.net> - 2011-10-29 15:42 -0400
    Re: missing variable Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-29 23:35 +0200
      Re: missing variable bill <nobody@spamcop.net> - 2011-10-30 08:59 -0400
        Re: missing variable Denis McMahon <denismfmcmahon@gmail.com> - 2011-10-30 19:57 +0000
          Re: missing variable Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-30 19:29 -0400
            Re: missing variable Denis McMahon <denismfmcmahon@gmail.com> - 2011-10-31 00:37 +0000
          Re: missing variable bill <nobody@spamcop.net> - 2011-10-31 06:30 -0400

#3621 — missing variable

Frombill <nobody@spamcop.net>
Date2011-10-29 15:42 -0400
Subjectmissing variable
Message-ID<-4adnYXjVd2CyjHTnZ2dnUVZ_oudnZ2d@cablespeedmi.com>
here is a tiny piece of my script:

$history = "empty appointment filled ";
echo  " history: $history\n";

when it executes I get a PHP Notice
PHP Notice:  Undefined variable: history in 
/var/www/MP2010-v2/classes/cSchedule.php on line 108

however if I use:
$history = "xxx";
echo  " history: $history\n";

it executes fine.

To say I am puzzled is a vast understatement.
Yes, I did cut an paste from the script,
No, I did not include the other  200 lines.
If I paste it into a test script, it runs fine so it is obviously 
in the other 200 lines.

If I rename the variable "hist" I get the same error

THis is running from the command line.

any thoughts ?

bill


[toc] | [next] | [standalone]


#3622

FromThomas Mlynarczyk <thomas@mlynarczyk-webdesign.de>
Date2011-10-29 23:35 +0200
Message-ID<j8hrj3$tls$1@news.albasani.net>
In reply to#3621
bill schrieb:

> $history = "empty appointment filled ";
> echo  " history: $history\n";

Looks okay to me.

> when it executes I get a PHP Notice
> PHP Notice:  Undefined variable: history in 
> /var/www/MP2010-v2/classes/cSchedule.php on line 108

Assuming the two lines of code above are 107 and 108 (and that you 
indeed copypasted them) I see no reason for this error.

> however if I use:
> $history = "xxx";
> echo  " history: $history\n";
> it executes fine.

Just replacing "empty appointment filled " in the above code with "xxx" 
has this effect? That simply cannot be.

> To say I am puzzled is a vast understatement.

 From my own experience I can tell that such incomprehensible behaviour 
usually indicates a very simple mistake.

> If I paste it into a test script, it runs fine so it is obviously in the 
> other 200 lines.

So we will obviously need to see those other lines. Maybe you can trim 
them down somewhat. And while doing this you might see the cause of the 
problem yourself.

> If I rename the variable "hist" I get the same error

Global search & replace? Or manually just in those two lines?

> THis is running from the command line.

Shouldn't matter, but one never knows.

Greetings,
Thomas


-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

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


#3627

Frombill <nobody@spamcop.net>
Date2011-10-30 08:59 -0400
Message-ID<BdCdneCS9Orf1zDTnZ2dnUVZ_vGdnZ2d@cablespeedmi.com>
In reply to#3622
On 10/29/2011 5:35 PM, Thomas Mlynarczyk wrote:
> bill schrieb:
>
>> $history = "empty appointment filled ";
>> echo " history: $history\n";
>
> Looks okay to me.
>
>> when it executes I get a PHP Notice
>> PHP Notice: Undefined variable: history in
>> /var/www/MP2010-v2/classes/cSchedule.php on line 108
>
> Assuming the two lines of code above are 107 and 108 (and that
> you indeed copypasted them) I see no reason for this error.
>
>> however if I use:
>> $history = "xxx";
>> echo " history: $history\n";
>> it executes fine.
>
> Just replacing "empty appointment filled " in the above code with
> "xxx" has this effect? That simply cannot be.
>
>> To say I am puzzled is a vast understatement.
>
>  From my own experience I can tell that such incomprehensible
> behaviour usually indicates a very simple mistake.
>
>> If I paste it into a test script, it runs fine so it is
>> obviously in the other 200 lines.
>
> So we will obviously need to see those other lines. Maybe you can
> trim them down somewhat. And while doing this you might see the
> cause of the problem yourself.
>
>> If I rename the variable "hist" I get the same error
>
> Global search & replace? Or manually just in those two lines?
>
>> THis is running from the command line.
>
> Shouldn't matter, but one never knows.
>
> Greetings,
> Thomas
>
>

Here is the top half of the function, as it works:
---
public function mCreateAppointment($user, $apptTime, $location, 
$duration, $standing, $ptNum, $notify, $comment )   { // create a 
new appointment - may be non-pt or empty
   // look for identical empty appointment
   $sql = "select schedule_id
      from schedule
      where user='$user' and
      apptTime = '$apptTime'and
      duration = '$duration' and
      appt_status = 'e'
      limit 1";
      $result =mysql_query( $sql, $this->connection) or 
die("MySql ERROR in cSchedule on line " . __LINE__ . "  " . 
mysql_error()) ;

  if (mysql_num_rows($result)) { // found an identical empty 
appt, use it
     $row =  mysql_fetch_array($result);
     $id = $row['schedule_id'];
     if ($ptNum == "empty") return // do nothing, do not need to 
create an empty appointment, as there is already an identical one

   $hist = "";	
   $hist = "empty appointment filled ". nowUS() ." by " 
.$_SESSION['current_user'] . "\n";
	
   echo __CLASS__ . "-" . __FUNCTION__ . ": " . __LINE__ . " 
history: $hist\n";

   $sql = "update schedule set
     user = '$user',
     location='$location',
     standing_script = '$standing',
     appt_status = 'a',
     patient_number = '$ptNum',
     notify = '$notify',
     comment = '$comment',
     history = concat(history, '$hist')
     where schedule_id ='$id' ";
echo __CLASS__ . "-" . __FUNCTION__ . ": " . __LINE__ . " 
sql=$sql\n-------------------------------------------------------------\n";

    $result = mysql_query( $sql, $this->connection) or die("MySql 
ERROR in cSchedule on line " . __LINE__ . "  " . mysql_error()) ;
     return;
     } //found an identical empty appt, use it

note:
   $hist = "";	
   $hist = "empty appointment filled ". nowUS() ." by " 
.$_SESSION['current_user'] . "\n";

If I remove the first line ($hist = "") I get the error message. 
  If I have both line in, the correct text is assigned to hist.

There are only 3 references to hist in the procedure, the two 
lines above and the sql.

Although I hate to do this, I am willing to leave the null 
assignment to keep the script running, but I sure would like to 
know what is going on.

bill

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


#3628

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2011-10-30 19:57 +0000
Message-ID<4eadac1b$0$28493$a8266bb1@newsreader.readnews.com>
In reply to#3627
On Sun, 30 Oct 2011 08:59:44 -0400, bill wrote:

>      if ($ptNum == "empty") return // do nothing, do not need to
> create an empty appointment, as there is already an identical one
>    $hist = "empty appointment filled ". nowUS() ." by "
> .$_SESSION['current_user'] . "\n";

No ";" after the preceding "return"

so without the $hist=""; line what you have is:

if ($ptNum == "empty") return $hist = "empty appointment filled ". nowUS
() ." by "   .$_SESSION['current_user'] . "\n";

In other words, the first $hist value after the return is only defined if 
it's being returned from the function, because it comes between the if 
($ptNum == "empty") and the next ";"

The // only creates comments to the end of line, it doesn't terminate the 
return

So your if statement assigns the $hist value and immediately uses it as 
the return value, when what you want is to assign the value if you didn't 
return.

Rgds

Denis McMahon

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


#3629

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-30 19:29 -0400
Message-ID<j8kmkp$s1n$1@dont-email.me>
In reply to#3628
On 10/30/2011 3:57 PM, Denis McMahon wrote:
> On Sun, 30 Oct 2011 08:59:44 -0400, bill wrote:
>
>>       if ($ptNum == "empty") return // do nothing, do not need to
>> create an empty appointment, as there is already an identical one
>>     $hist = "empty appointment filled ". nowUS() ." by "
>> .$_SESSION['current_user'] . "\n";
>
> No ";" after the preceding "return"
>
> so without the $hist=""; line what you have is:
>
> if ($ptNum == "empty") return $hist = "empty appointment filled ". nowUS
> () ." by "   .$_SESSION['current_user'] . "\n";
>
> In other words, the first $hist value after the return is only defined if
> it's being returned from the function, because it comes between the if
> ($ptNum == "empty") and the next ";"
>
> The // only creates comments to the end of line, it doesn't terminate the
> return
>
> So your if statement assigns the $hist value and immediately uses it as
> the return value, when what you want is to assign the value if you didn't
> return.
>
> Rgds
>
> Denis McMahon

Good eye, Dennis.  I completely  missed that one.

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

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


#3630

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2011-10-31 00:37 +0000
Message-ID<4eadeddd$0$28506$a8266bb1@newsreader.readnews.com>
In reply to#3629
On Sun, 30 Oct 2011 19:29:30 -0400, Jerry Stuckle wrote:

> On 10/30/2011 3:57 PM, Denis McMahon wrote:

>> No ";" after the preceding "return"

> Good eye, Dennis.  I completely  missed that one.

Yeah, I think the comment delimiter was visually masking the absence of 
the terminator.

Rgds

Denis McMahon

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


#3640

Frombill <nobody@spamcop.net>
Date2011-10-31 06:30 -0400
Message-ID<rfGdnZz2AtZL5TPTnZ2dnUVZ_sKdnZ2d@cablespeedmi.com>
In reply to#3628
On 10/30/2011 3:57 PM, Denis McMahon wrote:
> On Sun, 30 Oct 2011 08:59:44 -0400, bill wrote:
>
>>       if ($ptNum == "empty") return // do nothing, do not need to
>> create an empty appointment, as there is already an identical one
>>     $hist = "empty appointment filled ". nowUS() ." by "
>> .$_SESSION['current_user'] . "\n";
>
> No ";" after the preceding "return"
>
> so without the $hist=""; line what you have is:
>
> if ($ptNum == "empty") return $hist = "empty appointment filled ". nowUS
> () ." by "   .$_SESSION['current_user'] . "\n";
>
> In other words, the first $hist value after the return is only defined if
> it's being returned from the function, because it comes between the if
> ($ptNum == "empty") and the next ";"
>
> The // only creates comments to the end of line, it doesn't terminate the
> return
>
> So your if statement assigns the $hist value and immediately uses it as
> the return value, when what you want is to assign the value if you didn't
> return.
>
> Rgds
>
> Denis McMahon

Good catch.  Thank you so much !
bill

[toc] | [prev] | [standalone]


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


csiph-web