By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

Performance-define Vs. global vars

P: n/a
I'm interested to know which one is better--define or global variables
especially for config stuffs.
For example, osCommerce use something like: define('db_user', 'xx');
whereas phpMyAdmin uses like $config['server']['host'] =
'localhost';
and other few software use $db_pass = 'foo';

I'm much interested to know which one is good. Isn't hash array
like $config['server']['host'] overkill? TIA

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab**************************@posting.google.c om...
I'm interested to know which one is better--define or global variables
especially for config stuffs.
For example, osCommerce use something like: define('db_user', 'xx');
whereas phpMyAdmin uses like $config['server']['host'] =
'localhost';
and other few software use $db_pass = 'foo';

I'm much interested to know which one is good. Isn't hash array
like $config['server']['host'] overkill? TIA

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com


Using define is a little better, since you don't run the risk of the
configuration being tampered with even if your application is running on a
server with register_globals turned on. Having said that, I must say that I
usually use $NAME, so that I can interpolate the value into strings.

In regards to performance, getting a constant should be quicker in theory,
since there's no need to resolve variable scope. The difference is hardly
something that you would lose sleep over though.
Jul 17 '05 #2

P: n/a
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<eq********************@comcast.com>...
I'm interested to know which one is better--define or global variables
especially for config stuffs.
For example, osCommerce use something like: define('db_user', 'xx');
whereas phpMyAdmin uses like $config['server']['host'] =
'localhost';
and other few software use $db_pass = 'foo';

I'm much interested to know which one is good. Isn't hash array
like $config['server']['host'] overkill? TIA


Using define is a little better, since you don't run the risk of the
configuration being tampered with even if your application is running on a
server with register_globals turned on. Having said that, I must say that I
usually use $NAME, so that I can interpolate the value into strings.

In regards to performance, getting a constant should be quicker in theory,
since there's no need to resolve variable scope. The difference is hardly
something that you would lose sleep over though.


Thanks Chung, for your wonderful comments and thoughts.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.