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

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

 



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?

Many thanks for your reply,

M is for Murray


On Sat, Dec 27, 2008 at 5:00 PM, Larry Garfield <larry@xxxxxxxxxxxxxxxx>wrote:

> On Friday 26 December 2008 11:54:30 pm Murray wrote:
> > Hi All,
> >
> > In the index.php file of my application I define several variables,
> > including such things as the base path of the app, and the theme path
> etc.
> >
> > Since I use 'define()' to do this, are these variables available to my
> app
> > regardless of where a particular user enters the app?
> >
> > So, in starting the app, I define these variables by visiting index.php.
> > But if another user gets sent a url to, for example, the help page, when
> > they visit it will those variables be available, or will I need to
> > explicitly check on each to make sure the variables are defined, because
> > the user entered at a different entry point than the 'normal' one?
> >
> > Note: I will probably do an explicit check anyway, since this seems more
> > robust, but I ask to better understand how define works.
> >
> > Many thanks,
> >
> > M is for Murray
>
> Well, there is no such thing as a "defined variable".  You are, I presume,
> talking about constants.  (That's what you get from define().)  A global
> constant (vis, not a class constant) is "super-global", that is, available
> absolutely everywhere after the line of code that defines it has executed.
>
> So if the user goes to index.php, and the first line defines a constant
> DEBUG_LEVEL, then that constant now exists anywhere in any function or
> method
> for the rest of that page request, period.
>
> However, if someone goes to help.php then the line in index.php is never
> executed (why would it be, since the file was never included?), so the
> constant
> is not defined.
>
> Does that make sense?
>
> --
> Larry Garfield
> larry@xxxxxxxxxxxxxxxx
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[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