Hi,
What is the best choice for languages, config., settings &...?
Define or Variable? Why?
Thanks, regards.
Printable View
Hi,
What is the best choice for languages, config., settings &...?
Define or Variable? Why?
Thanks, regards.
I don't understand what you're trying to ask at all.
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']= '';
??
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).