PHPCase Sensitivity Rules

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
<?php

$userName = 'Amara';
$UserName = 'Beto';
$USERNAME = 'Chidi';

echo $userName;  // Amara
echo $UserName;  // Beto
echo $USERNAME;  // Chidi
AmaraBetoChidi
The classic typo bug
Mixing up the case of a variable name is one of the most common silent bugs for PHP beginners, because it doesn't throw a fatal error by default — it just produces a warning (`Undefined variable`) and evaluates to `null`, which can quietly propagate through the rest of the script.

A bug that looks fine at a glance

PHP
<?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
<?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
<?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
Constants are the one exception worth flagging
Constants created with `define()` can optionally be made case-sensitive via a third argument in very old PHP versions, but that option was removed in PHP 8 — `define()` constants, `const` class constants, and enum cases are now always matched case-sensitively, just like variables. `define('MAX_USERS', 100)` and referencing `max_users` will not resolve.
Case-sensitivity at a glance

Identifier type

Case-sensitive?

Variables ($name)

Yes

Array keys (string keys)

Yes

Function names (built-in and user-defined)

No

Language keywords (if, echo, function, class)

No

Class and interface names

No

Method names

No

Class constants and define() constants

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
<?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
    }
}
  • $variable names 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.

Tip
Enable your IDE's "undefined variable" inspection and run `php -l` (lint mode) or a static analyser like PHPStan on every file before committing. Neither will stop `EcHo` from running, but both will catch the far more damaging mistake of a mistyped variable case long before it reaches production.