Case Sensitivity Rules
PHP has an inconsistent, historically-grown relationship with letter case: some identifiers care about it and some don't, and the distinction isn't optional trivia — treating a case-insensitive name as case-sensitive (or vice versa) is a real source of "why doesn't this work" bugs. The short version: variables are case-sensitive, almost everything else is not — but "not case-sensitive" is far from "acceptable to write however you like."
Variables ARE case-sensitive
$name, $Name, and $NAME are three completely unrelated variables as far as PHP is concerned. There is no coercion, no warning, nothing that hints they might be the same thing — PHP silently treats the second one as undefined if you meant to reuse the first.
Three distinct variables
<?php $userName = 'Amara'; $UserName = 'Beto'; $USERNAME = 'Chidi'; echo $userName; // Amara echo $UserName; // Beto echo $USERNAME; // Chidi
AmaraBetoChidi
A bug that looks fine at a glance
<?php $totalPrice = 49.99; // ... 40 lines later, in a hurry ... echo "Total: $" . $TotalPrice; // Warning: Undefined variable $TotalPrice // Total: $
Functions and language constructs are NOT case-sensitive
Built-in function names, user-defined function names, and PHP's own keywords (if, else, foreach, return, echo, function, class, and so on) can be written in any letter case and PHP treats them identically. This is a historical quirk of PHP's earliest design and applies even to functions you write yourself.
Case has no effect on functions or keywords
<?php
function greetUser(string $name): string
{
RETURN "Hello, {$name}!";
}
ECHO greetUser('Divya');
echo GreetUser('Divya');
echo greetuser('Divya');
// All three calls above run the exact same function.Hello, Divya!Hello, Divya!Hello, Divya!
Classes and their methods are also case-insensitive by name
Class names, interface names, and method names follow the same relaxed rule. Note carefully that this applies to the name resolution, not to anything defined inside the class as data — a class constant or a property accessed dynamically by string still goes through PHP's regular (case-sensitive, for properties accessed as array-like strings) rules.
Class and method names ignore case
<?php
class InvoiceCalculator
{
public function applyTax(float $amount, float $rate): float
{
return $amount * (1 + $rate);
}
}
$calc = new invoicecalculator();
echo $calc->APPLYTAX(100, 0.08);108
Case-sensitivity at a glance
Identifier type | Case-sensitive? |
|---|---|
Variables ( | Yes |
Array keys (string keys) | Yes |
Function names (built-in and user-defined) | No |
Language keywords ( | No |
Class and interface names | No |
Method names | No |
Class constants and | Yes |
Namespaces | No (but treated case-preservingly by tooling) |
Case-insensitive doesn't mean "casing doesn't matter"
Just because PHP will happily run ECHO, EcHo, or echo doesn't mean you should pick at random. PSR-1 and PSR-12 — the community style standards followed by Composer packages, Laravel, and Symfony — mandate specific casing conventions: lowercase keywords, StudlyCaps for class names, camelCase for methods and properties, and UPPER_SNAKE_CASE for constants. Following them isn't about correctness, it's about every PHP developer being able to read your code without re-learning your personal conventions.
PSR-12 casing conventions in practice
<?php
class OrderShipment // StudlyCaps for classes
{
public const MAX_WEIGHT_KG = 30; // UPPER_SNAKE_CASE for constants
public function markAsDelivered(): void // camelCase for methods
{
// lowercase keywords
if ($this->isDelivered) {
return;
}
$this->isDelivered = true; // camelCase for properties
}
}$variablenames are matched exactly, case included — a mismatch silently creates or reads an undefined variable.Function names, keywords, class names, and method names all ignore case when PHP resolves them.
Class constants,
define()constants, and enum cases are always matched case-sensitively.Case-insensitivity is a parser rule, not a style licence — PSR-12 still expects consistent, conventional casing.