[thelist] [PHP] DEFINE Vs $variable..?

Rick den Haan rick.denhaan at gmail.com
Tue Feb 6 04:25:59 CST 2007


<snip>
My first thought was to simply set a session variable for each
Language...

However, I've seen sites (PHPMyAdmin springs to mind?) where the
language include uses DEFINE..

What is the difference, and why is one better than the other..?
</snip>

Tris,

There are three very big differences between variables and defines:

1. Once set, defines cannot be changed.
2. Defines, by default, are available in all scopes. No matter where
   they are defined, they are always available in any class or function.
3. Defines don't start with $ and *can* be (not are) case insensitive.

As to why one is better than the other in this particular situation,
I think it's just a matter of preference. When I do a multilingual
project, there tends to be a default language (usually English), and
then there are the custom languages. I tend to use variables, so I can
first include the English file, then include the other language as
needed so that it overwrites the default English values, but leaves
the English words that are missing in the translation.

Of course, if you know for a fact that the localized files are always
going to be complete, you could use defines.

HTH,
Rick.




More information about the thelist mailing list