[thelist] help me understand global variable in PHP

shawn allen shawn at alterior.net
Thu Jan 2 13:16:01 CST 2003


quoth Tom Dell'Aringa:
> > $prodname = $_REQUEST['prodname'];
> > $prodname = $_GET['prodname'];
>
> Yes, I am actually doing this in my target page...the second line
> $_GET as you specified. My problem isn't getting it there (I am able
> to get 2 other variables in that querystring). I need to get my
> variable that is set INSIDE the function available to me OUTSIDE of
> it.

Sorry, I should have looked at your code first. I guess I'm having
trouble understanding your problem then... If it's that $prodname isn't
being set in the global scope, you need to modify the $GLOBALS array
directly within your functions. So, instead of:

global $prodname;
$prodname = 'foo';

Try:

$GLOBALS['prodname'] = 'foo';

This goes for all those other variables ($tag, $insideproduct, etc.),
too. Also, you might want to consider using uppercase variable names to
distinguish global variables from local ones within your functions. It
would make your code a lot more readable. :)

--
shawn allen
  mailto://shawn@alterior.net
  phone://415.577.3961
  http://alterior.net
  aim://shawnpallen




More information about the thelist mailing list