RE: [PHP] Predefined Variables In Classes
| From: | John W. Holmes | Date: | Sun, 26 Jan 2003 21:37:26 +0000 |
| Subject: | RE: [PHP] Predefined Variables In Classes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-133198@lists.php.net to get a copy of this message | ||
> Well, I don't think this has anything to do with predefined variables
> being
> global or not because I only have use for them within the specific
> methods.
> The methods will capture their values and assign them to a variable
inside
> the function, which will return that variable at the end. The
processing
> of
> $PHP_SELF and $DOCUMENT_ROOT only happens in one place. I might be
wrong,
> not sure. But right now all I know is that I am confused and the link
you
> sent me didn't help explain what I need to know because it states no
> mention
> of predefined variables. Can you perhaps give me an example of what
you
> are
> trying to tell me?
Predefined or not, it's still a variable. If you want a variable inside
of your function to have the value of a variable outside of your
function, then you have to make it global. $PHP_SELF inside of your
function has no value because it's relative to the function, not the
script. Just like $a inside of a function wouldn't have a value unless
you assigned one to it. Using "global $PHP_SELF" at the beginning of
your function (or method, same thing) will now make the variable
$PHP_SELF have the same value as it does outside of your function.
> I read about variable scope and it says nothing about predefined
> variables.
> So how will using the $_SERVER associate array help me with this?
Remember
> that globals is on, so I don't need to use $_SERVER, $_POST, $_GET,
etc.
> to
> get my values. But, in the meantime I'll go ahead and try using the
> associate autoglobal arrays anyway, like $_SERVER, just to test it and
to
> see if it works for me. And if it does, it'll bug me until I find out
why
> it
> works. Thanks your input Philip. If anyone else has any thoughts or
> explainations for me to understad this then that would be great.
$_SERVER['PHP_SELF'] will always work, regardless of variable scope or
register_globals setting. The $_SERVER array is a superglobal, so it'll
have the same value inside your method or outside of it, without you
having to do anything special.
Hope that helps.
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/