Re: Variable scope

From: Date: Sat, 04 May 2002 19:52:27 +0000
Subject: Re: Variable scope
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-96075@lists.php.net to get a copy of this message
On Thu, 14 Mar 2002, George Nicolae wrote: >> > <? >> > function a($var_a) >> > { >> > b(); >> > } >> > >> > function b() >> > { >> > global $var_a; >> > echo $var_a; >> > } >> > >> > a("hello word!"); >> > ?> >> > >> > why function b() don't echo anything? >> >> Because $var_a has not, at any point, been defined in the global scope. > > how i declare $var_a as global? Define it somewhere within the global context (i.e., outside of any function. Or do what you have done, refer to it in function b() with the "global" keyword. But you can do that all day long and that won't make it local to function a() unless you modify that function as well. miguel

« previous php.general (#96075) next »