Performance-define Vs. global vars

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • R. Rajesh Jeba Anbiah

    Performance-define Vs. global vars

    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
  • Chung Leong

    #2
    Re: Performance-define Vs. global vars

    "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@r ediffmail.com> wrote in message
    news:abc4d8b8.0 407090359.16ec4 152@posting.goo gle.com...[color=blue]
    > 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[/color]

    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_global s 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.


    Comment

    • R. Rajesh Jeba Anbiah

      #3
      Re: Performance-define Vs. global vars

      "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message news:<eq2dnVkCC 9bMVm3dRVn-vg@comcast.com> ...[color=blue][color=green]
      > > 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[/color]
      >
      > 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_global s 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.[/color]

      Thanks Chung, for your wonderful comments and thoughts.

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

      Comment

      Working...