Re: [PHP] What am I not understanding about $GLOBALS['myvar'] vs global $myvar?

2003-03-27 Thread Ernest E Vogelsinger
At 09:24 27.03.2003, Marek Kilimajer said:
[snip]
echo GLOBALS['$key'] = $valuebr\n;
is right because $key is in double quotes (the outermost qoutes)
[snip] 

...almost... the array deref should be in curly quotes then:

echo {GLOBALS['$key']} = $valuebr\n;


-- 
   O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What am I not understanding about $GLOBALS['myvar'] vs global $myvar?

2003-03-27 Thread Ernest E Vogelsinger
At 09:46 27.03.2003, Marek Kilimajer said:
[snip]
there is no $ in front of GLOBALS ;)
[snip] 

right you are - I noticed it as soon as the message was out... sometimes
one's too fast hitting the send button ;-)


-- 
   O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] What am I not understanding about $GLOBALS['myvar'] vs global $myvar?

2003-03-26 Thread Daevid Vincent
How come this function works, but the one below does not?? 

function clearContactVars()
{
  global $contact_id;   $contact_id = ;
  global $contact_timestamp;$contact_timestamp = ;
  global $contact_incept;   $contact_incept = ;
  global $contact_dept_table_id;$contact_dept_table_id = ;
  global $contact_fname;$contact_fname = ;
  global $contact_lname;$contact_lname = ;
  global $contact_title;$contact_title = ;
  global $contact_phone;$contact_phone = ;
  global $contact_email;$contact_email = ;
  global $contact_address1; $contact_address1 = ;
  global $contact_address2; $contact_address2 = ;
  global $contact_city; $contact_city = ;
  global $contact_state;$contact_state = ;
  global $contact_zip;  $contact_zip = ;
  global $contact_country;  $contact_country = ;
  global $contact_notes;$contact_notes = ;
}

This one does NOT work the way I would expect it to?

function clearContactVars()
{
foreach ($GLOBALS as $key = $value) {
if ( substr($key,0,8) == contact_ ) {
  //echo GLOBALS['$key'] = $valuebr\n;
  $GLOBALS['$key'] = ;
}
}
clearPostVars();
}

(this is located in an require() file and do I even need to do this?):
function clearPostVars()
{   
foreach ($_POST as $key = $value) {
//echo _POST['$key'] = Value: $valuebr\n;
$_POST['$key'] = ;
}
}

I use these variables on a web page like so:

TR
TD ALIGN=RIGHTBPhone:/B/TD
TDINPUT Name=contact_phone Value=?=$contact_phone?/TD
/TR

So after a successful insert/update/whatever, I need to clear the fields.

The only other relevant part is that at the top of each page in a require()
file, I have this:

reset ($_POST);
while (list ($key, $val) = each ($_POST)) {
//echo $key = $valbr\n;
$$key = $val;
}

But it doesn't make sence to me that the first function does in fact clear
the variables, when the second one does not. I thought that would be even
more direct, since global $contact_id from what I read is only a reference
to the global variable named $contact_id. Which in effect should be exactly
$GLOBALS['contact_id'] right?
http://www.php.net/manual/tw/migration4.variables.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What am I not understanding about $GLOBALS['myvar'] vs global $myvar?

2003-03-26 Thread Daevid Vincent
Actually I didn't.  ;-)

$GLOBALS[$key] is incorrect and depricated AFAIK.
$GLOBALS['$key'] (with the single quotes) is the proper way to write these
types of associative arrays/hashs.

For shits and giggles however I tried your way and it made no difference to
the code. Still didn't work right.

 -Original Message-
 From: Marek Kilimajer [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, March 26, 2003 1:16 PM
 To: Daevid Vincent
 Cc: [EMAIL PROTECTED]
 Subject: Re: [PHP] What am I not understanding about 
 $GLOBALS['myvar'] vs global $myvar?
 
 
 
 
 Daevid Vincent wrote:
 
 This one does NOT work the way I would expect it to?
 
  function clearContactVars()
  {
  foreach ($GLOBALS as $key = $value) {
  if ( substr($key,0,8) == contact_ ) {
//echo GLOBALS['$key'] = $valuebr\n;
$GLOBALS['$key'] = ;
 
 I did not read your whole message, but you very likely mean
 
 $GLOBALS[$key] = ;
 (no single quotes)
 
  }
  }
  clearPostVars();
  }
 
   
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What am I not understanding about $GLOBALS['myvar'] vs global $myvar?

2003-03-26 Thread Johnson, Kirk
I think you either want to use no quotes or double quotes, but not single
quotes. Double quotes will interpolate the variable, single quotes will not,
i.e. $key becomes a string literal rather than a variable. No quotes will
work, although the docs seem to indicate it is deprecated syntax. Not
everyone agrees that it is deprecated, though ;)

Kirk

 $GLOBALS[$key] is incorrect and depricated AFAIK.
 $GLOBALS['$key'] (with the single quotes) is the proper way 
 to write these
 types of associative arrays/hashs.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What am I not understanding about $GLOBALS['myvar'] vs global $myvar?

2003-03-26 Thread Jennifer Goodie
Actually I didn't.  ;-)

$GLOBALS[$key] is incorrect and depricated AFAIK.
$GLOBALS['$key'] (with the single quotes) is the proper way to write these

Wouldn't it need to be $GLOBALS[$key] because single quotes tell the
parser not to expand variables? I think you are misinterpreting the part of
the manual that says You should always use quotes around an associative
array index.  Even though a variable may contain a string it is not a
string and therefore does not need quoting because there is not danger of it
being interpreted as a constant.  Look at the manual page on arrays, it
shows arrays with variable indices without quotes.
http://www.php.net/manual/en/language.types.array.php






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What am I not understanding about $GLOBALS['myvar'] vs global $myvar?

2003-03-26 Thread Leif K-Brooks
No, you misunderstand.  The key is simply a string.  Just as print 
foo; is wrong, $array[foo] is wrong (unless foo is a constant, of 
course).  If you do print '$variable';, it will print the literal 
string $variable.  It will not print the value of $variable.  You 
should either use double quotes or no quotes.

Johnson, Kirk wrote:

I think you either want to use no quotes or double quotes, but not single
quotes. Double quotes will interpolate the variable, single quotes will not,
i.e. $key becomes a string literal rather than a variable. No quotes will
work, although the docs seem to indicate it is deprecated syntax. Not
everyone agrees that it is deprecated, though ;)
Kirk

 

$GLOBALS[$key] is incorrect and depricated AFAIK.
$GLOBALS['$key'] (with the single quotes) is the proper way 
to write these
types of associative arrays/hashs.
   

 

--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt 
to decrypt it will be prosecuted to the full extent of the law.