PHP & Case Sensitivity

Manngo picture Manngo · Oct 22, 2015 · Viewed 40.3k times · Source

In PHP, variable and constant names are case sensitive, while function 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
  • Because Strings are case sensitive, anything that relies on strings, such as array keys and values, is also case sensitive

Answer

Abdulla Nilam picture Abdulla Nilam · Oct 22, 2015

FYI


Case sensitive (both user-defined and PHP defined)

  • variables
  • constants
  • array keys
  • class properties
  • class constants

Case insensitive (both user defined and PHP defined)

  • functions
  • class constructors
  • class methods
  • keywords and constructs (if, else, null, foreach, echo etc.)

In php.net

Basics

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscores, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'


Some useful Links

  1. Userland Naming Guide
  2. Why are functions and methods in PHP case-insensitive?
  3. Are PHP functions case sensitive?
  4. Are PHP keywords case-sensitive?
  5. Is PHP function names case-sensitive or not?
  6. Source of PHP Case Sensitive