Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Performance-define Vs. global vars
- R. Rajesh Jeba Anbiah
July 9, 2004, 9:59 am
rate this thread
especially for config stuffs.
For example, osCommerce use something like: define('db_user', 'xx');
whereas phpMyAdmin uses like $config['server']['host'] =
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 |
Re: Performance-define Vs. global vars
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.