Re: Confused - $GLOBALS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2004-12-09 at 13:41 -0500, John Nichel wrote:
> Danny Brow wrote:
> > Below is a snip of a program I am writing, I am a little new to php.
> > Any how, I can't for the life me figure out why one of my functions
> > cannot grab the item_pics1 variable. I have tried passing the variable
> > to the function, tried using $GLOBALS['item_pic1']. So I guess my
> > question is, does PHP in some cases need to have a variable in a if
> > statement sent back to the global scope? everything works but the
> > str_replace item_pics1. Hope this is enough code.
> <snip>
> 
> If you want to use a variable from outside the function, you either have 
> to pass it to the function; if you want to change it, you have to pass 
> it by reference, or make it global inside the function....
> 
> function foo ( $bar ) {
> 	/--code--/
> }
>
> function foo ( &$bar ) {
> 	/--code--/
> }
> 
> function foo() {
> 	global $var;
> 	/--more code--/
> }
> 
See this is where the confusion is, I've tried all these and it still
does not work.  I'm going to read the whole page on variable scope a few
times, see if I missed something.  Maybe it's something else in my code
screwing my up.

Thanks.
Dan.

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux