Page 1 of 1

difference bwt variable and constants

Posted: Wed Jan 20, 2010 5:33 am
by krsm1980
sry for my jargon....

this is just a newbie query....

define('FAVMOVIE', 'The Life of Brian');

This is treated as constant as per PHP obviously...

so my question is:

Will it work as GLOBAL variable throughout my session?

can we change the value of a constant run-time? if yes then what is the use of the constant, why not using just simple variable instead?

thanks for considering my question for your expert comments/answers...

Re: difference bwt variable and constants

Posted: Wed Jan 20, 2010 5:57 am
by papa
Why don't you try :)

Constants
A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script (except for magic constants, which aren't actually constants). A constant is case-sensitive by default. By convention, constant identifiers are always uppercase.

Re: difference bwt variable and constants

Posted: Wed Jan 20, 2010 6:53 am
by Jenk
The names are descriptive.. a Constant is constant, and a Variable can be variable.

Re: difference bwt variable and constants

Posted: Wed Jan 20, 2010 7:04 am
by krsm1980
papa wrote:Why don't you try :)

Constants
A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script (except for magic constants, which aren't actually constants). A constant is case-sensitive by default. By convention, constant identifiers are always uppercase.

thanks for making that more clear to me....

but what is the purpose of the constant?