[thelist] PHP: Equiv of CF Application.Scope?

Andrew Forsberg andrew at thepander.co.nz
Mon Mar 4 04:00:01 CST 2002


Hi,

>From my preliminary understanding of PHP, all variables (function
>locals excepted) seem to be global.

With register_globals on, this is true, however you can still address
different scopes directly, including the following arrays (old name /
new name (post v4.1) / description):

$HTTP_ENV_VARS / $_ENV -- environment variables
$HTTP_SERVER_VARS / $_SERVER -- server vars
$HTTP_GET_VARS / $_GET -- get vars
$HTTP_POST_VARS / $_POST -- post vars
$HTTP_POST_FILES / $_FILES -- info about files uploaded via post
$HTTP_COOKIE_VARS / $_COOKIE -- cookie vars
$HTTP_SESSION_VARS / $_SESSION -- session vars

Not quite sure about the order of precedence for the first two, but
the rest is right. i.e., post vars override get vars of the same
name, session vars override cookies, etc, but they're always directly
accessible through the arrays above. I find php code that explicitly
uses the arrays rather than the global equivalent easier to read and
debug. There's more info in the manual at:

http://www.php.net/manual/en/language.variables.predefined.php

>That's cool, but I'm wondering
>how I will be able to run multiple copies of an app without worrying
>about conflicts.

This is almost certain not to happen, it's managed internally by PHP
so one instance will not interfere with another (at least, I've never
heard of what you describe happening with PHP, and it would be
treated as a bug rather than something you have to code around). The
only exception I can think of is if somehow a session id of one user
was also simultaneously used by another -- but that'd be a rare and
unusual occasion that would cook scripts in any language.

>Does PHP have the equivalent of of CF's Application scope?

I don't know what that is -- is that where CF puts variables common
to all instances of the program? Read only variables of this type are
easy: just include a config file with all the variables you want.
Variables that are modifiable by every instance might be a bit
trickier -- a file system or database work-around could be coded,
though.

Cheers
Andrew

--



More information about the thelist mailing list