Why use constants?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Jeroen Oosterlaar
Forum Commoner
Posts: 37
Joined: Sun Nov 06, 2005 4:12 pm

Post by Jeroen Oosterlaar »

d11wtq wrote:Put simply....

You use constants where the value never needs to change
Use variables where the data can change (i.e. variable ;) )

Coding in other languages perhaps makes the distinction clearer :)
Yes, but practically you don't need to use constants. It is just a matter of definition and design as I said. As a programmer, you control what happens with the variables. It is not like you have to protect your software against yourself or something.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Jeroen Oosterlaar wrote:
d11wtq wrote:Put simply....

You use constants where the value never needs to change
Use variables where the data can change (i.e. variable ;) )

Coding in other languages perhaps makes the distinction clearer :)
Yes, but practically you don't need to use constants. It is just a matter of definition and design as I said. As a programmer, you control what happens with the variables. It is not like you have to protect your software against yourself or something.
You might have to if you have multiple personality syndrome... your other personality might want to change that variable to be mean.
Jeroen Oosterlaar
Forum Commoner
Posts: 37
Joined: Sun Nov 06, 2005 4:12 pm

Post by Jeroen Oosterlaar »

One armed space goat wrote:
Jeroen Oosterlaar wrote:
d11wtq wrote:Put simply....

You use constants where the value never needs to change
Use variables where the data can change (i.e. variable ;) )

Coding in other languages perhaps makes the distinction clearer :)
Yes, but practically you don't need to use constants. It is just a matter of definition and design as I said. As a programmer, you control what happens with the variables. It is not like you have to protect your software against yourself or something.
You might have to if you have multiple personality syndrome... your other personality might want to change that variable to be mean.
:lol:!
Post Reply