Re: Do defined variables exist at application scope, or session scope?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Dec 27, 2008 at 12:54 AM, Murray <planetthoughtful@xxxxxxxxx> wrote:

> Hi Larry,
>
> You're absolutely right, I'm talking about constants rather than variables.
>
> I guess in my very crude way, I'm trying to ask about the following:
>
> UserA goes to the site via index.php, which defines several helpful
> constants.
>
> So do UserB through UserF.
>
> UserG, however, first arrives at the site on help.php.
>
> Because UserA, UserB, UserC etc have been to index.php, which has now been
> executed, are the constants available with their values in help.php, even
> though UserG, in particular, started in the application at this point?
>
> So, another way of putting it, do these constants live for the life of the
> application per se (ie, presumably until the server is restarted etc), or
> will code in help.php be unable to access the values of defined constants
> for this particular user because they were not at index.php first?


no, global variables do not persist at a session level.

you could easily discover this with a simple test (following code untested
:)).

testDefineScope1.php
<?php
define('MY_GLOBAL', 5);
session_start();
$_SESSION['SESSION_VAR'] = 10;

testDefineScope2.php
<?php
var_dump($_SESSION['SESSION_VAR']);
var_dump(MY_GLOBAL);

test,

1. go to testDefineScope1.php
    . MY_GLOBAL will be defined for the duration of testDefineScope1.php's
execution
    . $_SESSION['SESSION_VAR'] will be placed into the session

2. go to testDefineScope2.php
  . $_SESSION['SESSION_VAR'] is in the session and will be displayed
  . MY_GLOBAL expired after testDefineScope1.php finished executing and
therefore a fatal should be raised at thte second statement

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux