Re: define() or $variable for application settings?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Matt:

That should've been my follow up question - which is, if define() is a
lot safer and more elegant to use than variables, why do many projects
use variables?

My use of CONSTANCE's and variables depend upon need. If I require a constant throughout the main() portion of my code, then I use define() and if I need something that is subject to change, then I use variables.

However, from my personal programming experience (for all languages), I find it best to write functions that are self contained -- that don't rely on global variables or constants. They simply receive what they need and return, if required, a result. If I place constants in them, then it's harder to reuse the code for other projects.

Some constants are truly constants, like PI -- while other constant elements change depending upon use, like db_name, user_id, and such. The use of constants depends upon your programming style and your ability to remain consistent in defining them.

Would you guys know why this is so? AFAIK, in compiled languages like
C, constants are faster because the preprocessor expands them at
compile-time rather than being allocated memory during run-time - but
then we're talking about PHP here.

It's my understanding that php is written in C.

tedd

--
--------------------------------------------------------------------------------
http://sperling.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux