RE: [PHP] define (true/false)
| From: | Jay Blanchard | Date: | Thu, 28 Jul 2005 12:46:50 +0000 |
| Subject: | RE: [PHP] define (true/false) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-219491@lists.php.net to get a copy of this message | ||
[snip]
>>if($bars == 3)
>>{
>> define('BAR', 1);
>>}
>>
>>then:
>>
>>if(BAR)
>>{
> That's an incorrect use for constants. Use variables for that =]
WHY?
[/snip]
Because the constant can be variable in this case. Consider (this is old
school, and we all know that I am the definition of old school) the
definition of the words themselves...variable and constant. You may want
to use a constant to determine a variable;
$myVar = CONSTANT + 3;
But you would never want to use a variable to determine a constant
because the variable is not likely to be the same (that is why we call
them variables) on any iteration. Using constants in expressions is OK,
for instance
if(BAR == $foo){
...stuff...
}
But modifying a constant is a no-no.