At 2:57 AM -0400 7/4/04, John W. Holmes wrote:
Michael Collins wrote:

I am relatively new at PHP and wondering why there is no mechanism to create user-defined superglobals? For example in ASP.Net I can setup a global.asa to define database connections or any named value I want to be available anywhere in an application. It would be great to have something like that in PHP.

You can do the same thing with a PHP file and have it auto_prepended to your scripts or just include() it yourself.


I think I will opt for the strategy to prepend a file using the auto_prepend_file directive in the php configuration file:

php_value auto_prepend_file /path/prepend.php

This was helpful (which I was able to find after getting the terminology of auto_prepend):

http://www.zend.com/zend/spotlight/prepend.php

At 3:12 AM -0400 7/4/04, Jason Barnett wrote:
About the only user-defined superglobals are constants. If you really want to get the value of a global variable while inside of a function, you could just use GLOBAL. Or if you REALLY wanted to, you could store the variables in the $_SESSION superglobal array. But I'm curious, why do you want superglobal-like access for your database connection?

In part, I am looking for a way to have a standardized library of functions that are available everywhere without having to do an include on every page. auto_prepend helps solve part of the issue but the trouble with auto_prepend_file, or with including the library on each page, is that php has to parse and process these pages for each and every script. For performance reasons it would be much better if certain values or code could be cached, as is the case with the ASP global.asa file. If the files and scope was limited to an application, or Web site, then a certain level of security should be possible.


--
Michael
__
||| Michael Collins
||| Kuwago Inc
||| Singapore and Seattle USA

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to