difference bwt variable and constants

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
krsm1980
Forum Commoner
Posts: 25
Joined: Sat Jan 09, 2010 12:33 am
Location: IN
Contact:

difference bwt variable and constants

Post 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...
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: difference bwt variable and constants

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: difference bwt variable and constants

Post by Jenk »

The names are descriptive.. a Constant is constant, and a Variable can be variable.
User avatar
krsm1980
Forum Commoner
Posts: 25
Joined: Sat Jan 09, 2010 12:33 am
Location: IN
Contact:

Re: difference bwt variable and constants

Post 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?
Post Reply