Re: [PHP] user-defined superglobals

2004-07-04 Thread Michael Gale
Hello,

I am not a programmer so I do not know if you can create a superglobal
variable. I am sure there is a problem with this ... any ways I user:

require(db_access.php); 

at the top of all my pages that require db access for a application that
way the db access gets set on a per page bases. Which would be safe then
a superglobal one.

Michael.



On Sun, 4 Jul 2004 14:22:09 +0800
Michael Collins [EMAIL PROTECTED] 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.
 
 -- 
 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
 

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



Re: [PHP] user-defined superglobals

2004-07-04 Thread John W. Holmes
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.

You can't make your own superglobals, but you can assign keys to the 
existing ones, if you really want.

$_SERVER['MY_DATABASE_USER'] = 'user';
$_SERVER['MY_DATABASE_PASS'] = 'pass';
mysql_connect('localhost',$_SERVER['MY_DATABASE_USER'],$_SERVER['MY_DATABASE_PASS']);
etc...
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] user-defined superglobals

2004-07-04 Thread Michael Collins
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


Re: [PHP] user-defined superglobals

2004-07-04 Thread Jason Barnett
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.

Well if you're looking for caching there are a couple of options 
available.  Zend and APC come to mind, YMMV.

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


Re: [PHP] user-defined superglobals

2004-07-04 Thread Steve Douville
Or if you wanted it to be pretty...

define('MY_DATABASE_USER', 'user');
define('MY_DATABASE_PASS', 'pass');

mysql_connect('localhost',MY_DATABASE_USER,MY_DATABASE_PASS);

- Original Message - 
From: John W. Holmes [EMAIL PROTECTED]
To: Michael Collins [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Sunday, July 04, 2004 2:57 AM
Subject: Re: [PHP] user-defined superglobals


 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.

 You can't make your own superglobals, but you can assign keys to the
 existing ones, if you really want.

 $_SERVER['MY_DATABASE_USER'] = 'user';
 $_SERVER['MY_DATABASE_PASS'] = 'pass';


mysql_connect('localhost',$_SERVER['MY_DATABASE_USER'],$_SERVER['MY_DATABASE
_PASS']);

 etc...

 -- 
 ---John Holmes...

 Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

 php|architect: The Magazine for PHP Professionals  www.phparch.com

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






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



Re: [PHP] user-defined superglobals?

2003-08-24 Thread Mike Migurski
It would be nice to have a php-function like

declare_superglobal($_MYFRAMEWORK);

And then use $_MYFRAMEWORK like $_GET.

You have a few options: if you are looking to set variables that are
static and atomic, you can use environmental variables in an .htaccess
file (getenv() to access them) or you can use read-only constants
(define() to create them).

If you need a global read-write or array variable, just use $_GLOBALS:
use $_GLOBALS['_MYFRAMEWORK'] like $_GET, etc.

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

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



Re: [PHP] user-defined superglobals?

2003-08-23 Thread Ray Hunter
you can define your own superglobals by defining the vars first then
accessing them thru the $GLOBALS var.

example:

?php
// file1.php
$var1 = test1\n;
$var2 = test2\n;
?

?php
// file2.php
include( 'file1.php' );

function test() {
  echo $GLOBALS['var1'];
  echo $GLOBALS['var2'];
  echo Test\n
}

test();

?

That should get you started with globals.

--
BigDog


On Sat, 2003-08-23 at 11:45, Matthias Nothhaft wrote:
 Hi List,
 
 is there a way (mybe in php5?) to define/declare a global var as a 
 superglobal, so that I can use this var like the known superglobals
 ($_GET, $_SESSION, etc.) ???
 
 If not, is there a list for feature requests?
 
 
 Regards,
 Matthias
 


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



Re: [PHP] user-defined superglobals?

2003-08-23 Thread Matthias Nothhaft
Hi Ray Hunter, you wrote:
you can define your own superglobals by defining the vars first then
accessing them thru the $GLOBALS var.
example:

?php
// file1.php
$var1 = test1\n;
$var2 = test2\n;
?
?php
// file2.php
include( 'file1.php' );
function test() {
  echo $GLOBALS['var1'];
  echo $GLOBALS['var2'];
  echo Test\n
}
test();

?

That should get you started with globals.

Well, this is clear, (I'm only new in the list - not in PHP ;-) )
but I want it in a better/shorter way
for the master var of a big project!
Is there a way to request such a feature and where?
I think this would be nice for application frameworks!?
Maybe also for PEAR...
Regards,
Matthias

--
BigDog
On Sat, 2003-08-23 at 11:45, Matthias Nothhaft wrote:

Hi List,

is there a way (mybe in php5?) to define/declare a global var as a 
superglobal, so that I can use this var like the known superglobals
($_GET, $_SESSION, etc.) ???

If not, is there a list for feature requests?

Regards,
Matthias





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


Re: [PHP] user-defined superglobals?

2003-08-23 Thread Tom Rogers
Hi,

Sunday, August 24, 2003, 3:45:33 AM, you wrote:
MN Hi List,

MN is there a way (mybe in php5?) to define/declare a global var as a 
MN superglobal, so that I can use this var like the known superglobals
MN ($_GET, $_SESSION, etc.) ???

MN If not, is there a list for feature requests?


MN Regards,
MN Matthias

You can always add to one of the superglobals, remembering not to have
a name clash with get or post variables.

$_GET['test'] = 'Hi;

now that will be available in all functions.

-- 
regards,
Tom


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



Re: [PHP] user-defined superglobals?

2003-08-23 Thread Matthias Nothhaft
Sorry this all is not what I'm looking for.
I see it is not possible at the moment.
It would be nice to have a php-function like

declare_superglobal($_MYFRAMEWORK);

And then use $_MYFRAMEWORK like $_GET.

Thanks nevertheless.

Regards,
Matthias
Ray Hunter wrote:
Well, this is clear, (I'm only new in the list - not in PHP ;-) )
but I want it in a better/shorter way
for the master var of a big project!


Yes you can set up a master file that includes all your master
vars...many php developers call this a configuration script and name it
config.php.
This allows users to set up global variables that are used through out
the application.

Is there a way to request such a feature and where?
I think this would be nice for application frameworks!?
Maybe also for PEAR...


There are implementations of this all thru PEAR.

--
BigDog




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


Re: [PHP] user-defined superglobals?

2003-08-23 Thread Jim Lucas
I have been wanting the same thing, but I too have not found a solution, and
do not know if it will come around.

Being able to create your own super-global would be a very nice feature.

Jim Lucas
- Original Message - 
From: Matthias Nothhaft [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, August 23, 2003 11:44 AM
Subject: Re: [PHP] user-defined superglobals?


 Sorry this all is not what I'm looking for.
 I see it is not possible at the moment.

 It would be nice to have a php-function like

 declare_superglobal($_MYFRAMEWORK);

 And then use $_MYFRAMEWORK like $_GET.

 Thanks nevertheless.

 Regards,
 Matthias

 Ray Hunter wrote:
 Well, this is clear, (I'm only new in the list - not in PHP ;-) )
 but I want it in a better/shorter way
 for the master var of a big project!
 
 
  Yes you can set up a master file that includes all your master
  vars...many php developers call this a configuration script and name it
  config.php.
 
  This allows users to set up global variables that are used through out
  the application.
 
 
 Is there a way to request such a feature and where?
 I think this would be nice for application frameworks!?
 Maybe also for PEAR...
 
 
  There are implementations of this all thru PEAR.
 
  --
  BigDog
 
 
 



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



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



Re: [PHP] user-defined superglobals?

2003-08-23 Thread Curt Zirzow
* Thus wrote Matthias Nothhaft ([EMAIL PROTECTED]):
 Hi List,
 
 is there a way (mybe in php5?) to define/declare a global var as a 
 superglobal, so that I can use this var like the known superglobals
 ($_GET, $_SESSION, etc.) ???
 
 If not, is there a list for feature requests?

You can request features at bugs.php.net. there is a type of bug
called 'Feature/Change Request'.  

Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

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



Re: [PHP] user-defined superglobals?

2003-08-23 Thread Jason Sheets
Someone wrote a php module that did this around 6 to 9 months ago.  It 
was easy to install but you needed access to php.ini.

Try using extract with the option to use references so you don't create 
a copy of the variable just a pointer to it.

Jason

Matthias Nothhaft wrote:

Sorry this all is not what I'm looking for.
I see it is not possible at the moment.
It would be nice to have a php-function like

declare_superglobal($_MYFRAMEWORK);

And then use $_MYFRAMEWORK like $_GET.

Thanks nevertheless.

Regards,
Matthias
Ray Hunter wrote:

Well, this is clear, (I'm only new in the list - not in PHP ;-) )
but I want it in a better/shorter way
for the master var of a big project!


Yes you can set up a master file that includes all your master
vars...many php developers call this a configuration script and name it
config.php.
This allows users to set up global variables that are used through out
the application.

Is there a way to request such a feature and where?
I think this would be nice for application frameworks!?
Maybe also for PEAR...


There are implementations of this all thru PEAR.

--
BigDog





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


Re: [PHP] user-defined superglobals?

2003-08-23 Thread Matthias Nothhaft
Hi Jason Sheets, you wrote:
Someone wrote a php module that did this around 6 to 9 months ago.  It 
was easy to install but you needed access to php.ini.
Do you know where to get/download this module?

Regards,
Matthias
Try using extract with the option to use references so you don't create 
a copy of the variable just a pointer to it.

Jason

Matthias Nothhaft wrote:

Sorry this all is not what I'm looking for.
I see it is not possible at the moment.
It would be nice to have a php-function like

declare_superglobal($_MYFRAMEWORK);

And then use $_MYFRAMEWORK like $_GET.

Thanks nevertheless.

Regards,
Matthias
Ray Hunter wrote:

Well, this is clear, (I'm only new in the list - not in PHP ;-) )
but I want it in a better/shorter way
for the master var of a big project!




Yes you can set up a master file that includes all your master
vars...many php developers call this a configuration script and name it
config.php.
This allows users to set up global variables that are used through out
the application.

Is there a way to request such a feature and where?
I think this would be nice for application frameworks!?
Maybe also for PEAR...




There are implementations of this all thru PEAR.

--
BigDog








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