You are here: Re: [PHP] define (true/false) « PHP « IT news, forums, messages
Re: [PHP] define (true/false)

Posted by Jochem Maas on 10/29/26 11:22

John Nichel wrote:
> Jay Blanchard wrote:
>
>> [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.
>>
>
> I may be misunderstanding you here, but I don't see why you would not
> want to use a variable to define a constant. I do it from time to time,
> most common would be in a config document where I'll check if the page
> is being accessed via http or https, and define a constant based on
> that. I know I could use a variable for this, but I like using the
> constant for it's global scope in that case.

now that was exactly my reasoning ... but I very much appriciate the input
of the more experienced/older/classically-trained (as apposed to my completely
-self-taught-not-backed-up-with-any-solid-computer-science-theory-skills)
guys out there (hey Jay it's a compliment ;-)

>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация