What is the difference and/or benefit of using define. for example in db file i can define password or any variable that i am going to use throughout website like this:
define('DB_PASSWORD', 'mypassword');
Instead of above code, I can also use it in db file like this:
$DB_PASSWORD="mypassword";
Both will serve same purpose…
db file will be included in every page of website. So is there any benefit of using define rather then just declaring a variable.
Define defines a value, a constant which you can not change while variable means it’s value may or will vary.
EDIT:
Both have practical usage. There are sometimes data which should not be changed or it is always the same. For example a hex code of color blue will always be
0000FFor a database password may never be changed while the session is running.It’s more of a security tool than a performance or readability concern. Once you
DEFINE, there’s no way back, but you’re sure your data is the same across the whole instance.