[RESOLVED] Define or Variable(For languages, config....)-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] Define or Variable(For languages, config....)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    157

    Resolved [RESOLVED] Define or Variable(For languages, config....)

    Hi,
    What is the best choice for languages, config., settings &...?
    Define or Variable? Why?
    Thanks, regards.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Define or Variable(For languages, config....)

    I don't understand what you're trying to ask at all.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    157

    Re: Define or Variable(For languages, config....)

    For example, this is my database config.: host, port, username, password...
    What is the best choice? Define or Variable?

    define('Host', '127.0.0.1');
    define('Port', 3306);
    define('Username', 'root');
    define('Password', '');

    or

    $cfg['Host']= '127.0.0.1';
    $cfg['Port']= 3306;
    $cfg['Username']= 'root';
    $cfg['Password']= '';

    ??

  4. #4
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,500

    Re: Define or Variable(For languages, config....)

    Defined constants have global scope, and cannot be changed in the script. Therefore they ought to be data that meets those criteria: globally used values that will not need to change. For your example, I would say define is more appropriate (though I would use more specific naming, like "DB_USERNAME" - also the naming convention for constants is all caps).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.