RE: [PHP] registering session variables doesn't work in functions
| From: | John W. Holmes | Date: | Tue, 05 Dec 2000 02:48:58 +0000 |
| Subject: | RE: [PHP] registering session variables doesn't work in functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31730@lists.php.net to get a copy of this message | ||
Yes, because within the function, the variable has a value. When you
register the variable, PHP remembers the variables name, then at then end of
the script it saves it's value. It doesn't save the value where you call
session_register(), otherwise you wouldn't have this problem. At the end of
the script, $foo does not have a value because it's scope was only for the
function.
function do_this()
{
global $foo;
session_register($foo);
$foo = "whatever";
$foo .= " you want";
}
Something like that should work. It'll keep the value of $foo alive outside
of the function and at the end of the script, it's value will be saved.
---John Holmes...
-----Original Message-----
From: Wayne Pascoe [mailto:wayne@penguinpowered.org.uk]On Behalf Of A
Complete Luser
Sent: Sunday, December 24, 2000 11:41 AM
To: John W. Holmes
Subject: Re: [PHP] registering session variables doesn't work in
functions
"John W. Holmes" <john@sepodaticreations.com> writes:
> It's got to be a variable scope issue. You can register a variable, and
PHP
> will save that variables value at the end of the script. The problem is
that
> at the end of the script, PHP is outside of the function, so that variable
> doesn't have a value anymore. I'm assuming that's what happens. You can
make
> your variables global within your function, then it should work.
>
> ---John Holmes...
That doesn't make sense... In the same function where registering them
doesn't work, I can do
printf("Variable Foo is %s",$foo);
and the value is printed as I expect it to be.
But when I do a
session_register("foo");
no value is registered...
--
A Complete Luser <acompleteluser@penguinpowered.org.uk>