NYCPHP Meetup

[nycphp-talk] define variables versus assigned variables

webmaster at vbplusme.com webmaster at vbplusme.com
Sun Jan 3 07:48:41 EST 2010


Hello Eddie,

Sunday, January 3, 2010, 3:25:22 PM, you wrote:

> The primary difference between a variable and a constant is
> mutability.  If your database authorization details are not going to
> change, make them constants.  If your database details DO change
> throughout the execution of a script, make them variables.  In regards
> to the performance of constants in PHP, that's an incredibly minor
> improvement (a microoptimization, really) and it's my opinion that you
> ought to be writing software to be good code and not have to hack
> around considerations like how many microseconds your database
> username declaration takes.

> My advice: use constants for script immutable values and variables for
> mutable values.  If you want to have a class constant, do that, but
> it's not worth the hassle to write a class around the idea that class
> constants are faster than global constants.  Use which tool is right
> for the job.  Depending on the structure of your application,
> DatabaseClass::USERNAME might make more sense than DB_USERNAME, but
> that decision ought to be dictated by the structure of your code, not
> some small performance consideration.

> -Eddie

Gotcha, thanks for the guidance. I think I have a better understanding
about it now. 

-- 
Best regards,
 Webmaster                            mailto:webmaster at vbplusme.com




More information about the talk mailing list