I can't speek about the first problem, but about the second one.

You are not setting the variable $blah as a global variable.

Try this instead

$GLOBALS['blah'] = 'bob';

and that should work.

You need to look into scope when refering to variables and functions.

Jim Lucas

----- Original Message ----- 
From: "Chris Boget" <[EMAIL PROTECTED]>
To: "PHP General" <[EMAIL PROTECTED]>
Sent: Friday, August 01, 2003 12:03 PM
Subject: [PHP] Globals


> I'm curious if someone could explain to me why this is occuring:
> 
> function blah() {
>   //global $GLOBALS;
> echo 'Globals: <pre>'; print_r( $GLOBALS ); echo '</pre>';
> 
> }
> 
> As it is shown above, with the 'global $GLOBALS' line commented
> out, the print_r() works and shows all the currently defined variables
> and their corresponding values.  However, if I declare $GLOBALS
> as global, nothing gets printed out.
> 
> Why?
> 
> Wouldn't the 'global $GLOBALS' line be more or less redundant in
> most cases?  Because $GLOBALS is a superglobal (though, it isn't
> really)?  Why would it affect whether or not $GLOBALS actually has
> the expected data inside the function?
> 
> While I'm on this subject, why isn't $GLOBALS always a superglobal?
> For example, this doesn't work:
> 
> function innerFunc() {
> 
>   echo $GLOBALS['blah'];
> 
> }
> 
> function outerFunc() {
> 
>   innerFunc();
> 
> }
> 
> $blah = 'bob';
> outerFunc();
> 
> Nothing gets echoed from innerFunc().  Why?  If anyone can offer
> any insight as to what is going on, I'd be ever so appreciative.
> 
> Chris
> 
> 
> -- 
> 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

Reply via email to