In PHP, variable and constant names are case sensitive, while function names and class names are not.
As far as I am aware, PHP is the only language in which this happens. All other languages I have used are either totally case sensitive or totally case insensitive.
Why is PHP partially case senstive?
Please note, that I am not asking which names are case sensitive, but why.
Update
I thought I might add, for the benefit of those who think I am asking which, the following list:
Case Sensitive
- Strings
- Variables
- Object Properties
- Constants, by default
Case Insensitive
- Key Words etc
- Functions
- Object Methods
- Constants, if defined accordingly
- Class Names
Note:
- Classes are thus a mixed bag:
- The
class
keyword is case insensitive - Class names are case insensitive, for declaration, instantiation, and static calls
- Class methods, being functions, are case insensitive
- Class properties, being variables & constants, are case sensitive
- The
- Because Strings are case sensitive, anything that relies on strings, such as array keys and values, is also case sensitive
why
, maybe they designed the language that way. But it is a good practice toconsider PHP as case-sensitive
and use the functions/variables as declared. – AlienationMyClass
has already been loaded,MyClass::XX
andmyclass::XX
will both work. If the autoloader is case sensitive, the class has not been loaded yet and you try to usemyclass::XX
, it would fail. – Exarate