On Sunday 28 April 2002 04:39, Henrik Hansen wrote:
> [EMAIL PROTECTED] (John Hughes) wrote:
>  > Can someone point me toward a tutorial on the proper use of global
>  > references under PHP4.

The manual has very good information.

>  >
>  > I have been declaring
>  >
>  > function something()
>  > {
>  > global $foo, $bar;
>  >
>  > /* some actions */
>  >
>  > }
>  >
>  > in functions and I understand that this is not the way I'm supposed
>  > to be doing this. Or there is a new way that is preferred.

That is a perfectly valid declaration, but without knowing your intent one 
cannot say whether it is 'right' or 'wrong'.

The thing you need to remember with PHP is that unlike many other languages, 
by default variables are not global in nature. Thus in order to use a 
variable that is defined outside of a function you need to declare it like 
you have above.

> you can do it that way, but if you want to avoid calling global all
> the time you might consider this approach:
>
> $GLOBALS["foo"] = 123;

  $foo = 123; # No need to use the $GLOBALS array when outside of a function

> function something()
> {
>     echo $GLOBALS["foo"];
> }

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
"...if the church put in half the time on covetousness that it does on lust,
 this would be a better world."  - Garrison Keillor, "Lake Wobegon Days"
*/

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

Reply via email to