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

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

 



tedd wrote:
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


Consants are very good for multilingual sites.

Well and the name it self says what they are for:
To be constant.

So vars which have the constant same value should be defined as constants.

That's how i see that.

And safe, well. if php is safe, the vars in it are also.

Barry

--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

--
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