Re: global $HTTP_SESSION_VARS not global ???
| From: | Herouth Maoz | Date: | Tue, 11 Sep 2001 06:06:41 +0000 |
| Subject: | Re: global $HTTP_SESSION_VARS not global ??? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-66854@lists.php.net to get a copy of this message | ||
On 2001 September? 10 ,Monday 18:56, Thomas Watson wrote:
> <?php
>
> session_start();
> session_register("test");
> $test = "something";
>
> function foo() {
> print($HTTP_SESSION_VARS["test"] . "<br />\n");
> }
>
> foo();
> print($HTTP_SESSION_VARS["test"] . "<br />\n");
>
> ?>
>
> <a href="<?=$PHP_SELF?>">Click here</a>
> -----------------------------------------------------------
>
> I would expect the array $HTTP_SESSION_VARS to be global, and
> thereby available inside the foo() function.
>
> Have I misunderstood something in the manual?
Yes, indeed. Global variables are not available inside functions,
unless declared with the global keyword. This is a peculiarity of PHP
(most other C-originating languages do it the other way - this is not
a statement of criticism, just a fact). The only exception to this
rule is the $GLOBALS array.
Herouth