Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 2000051

Re: [PHP3] Accessing global variables from within a class From: Wico de Leeuw (wico <email protected>)
Date: 05/15/00

Hiya

class Globals {
         function show_self() {
                 global $PHP_SELF;
                 print $PHP_SELF;
         }

}

should do the trick

Greetz,

Wico

At 10:32 15-5-2000 -0400, Vamsi Nath wrote:

>I have been having difficulty accessing global environmental variables like
>$PHP_SELF and $HTTP_USER_AGENT from within a class. Normally, to use these
>values in functions you have to specify them as 'global', but I get a parse
>error when I try declaring a global variable within a class definition.
>
>Example:
>
>class Globals {
> global $PHP_SELF;
>
> function show_self() {
> print $PHP_SELF;
> }
>
>}
>
>Results in parse error:
>Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or
>`T_VAR' or `'}''
>
>The only way I have been able to get around this is to define a CONSTANT
>outside the class definition.
>
>Example:
>
>define("PHP_SELF",$PHP_SELF);
>
>class Globals {
> function show_self() {
> print $PHP_SELF;
> }
>}
>
>This works, but seems less then optimal. Is there a way around this?
>Thanks for your help.
>
>--Vamsi Nath
>http://php.vamsi.net
>
>
>--
>PHP 3 Mailing List <http://www.php.net/>
>To unsubscribe, send an empty message to php3-unsubscribe <email protected>
>To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
>To search the mailing list archive, go to: http://www.php.net/mailsearch.php3
>To contact the list administrators, e-mail: php-list-admin <email protected>

-- 
PHP 3 Mailing List <http://www.php.net/>
To unsubscribe, send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
To search the mailing list archive, go to: http://www.php.net/mailsearch.php3
To contact the list administrators, e-mail: php-list-admin <email protected>