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

2003-03-27 Thread Marek Kilimajer
variables inside single quotes are not evaluated! This is the same variable:
echo $GLOBALS['var'];
$key='var'; echo $GLOBALS[$key];
With $GLOBALS['$key'] you refer to an invalid variable name $'$key'

PS: Output of

echo GLOBALS['$key'] = $valuebr\n;
is right because $key is in double quotes (the outermost qoutes)


Daevid Vincent wrote:

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'] vsglobal $myvar?

2003-03-27 Thread Marek Kilimajer
there is no $ in front of GLOBALS ;)

Ernest E Vogelsinger wrote:

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;

 



--
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'] vsglobal $myvar?

2003-03-26 Thread Marek Kilimajer


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