PHP is partly case-sensitive. That surprises many beginners, so learn the rule once.
Variables are case-sensitive
$name, $Name and $NAME are three different variables.
<?php
$name = "Sam";
$Name = "Tina";
echo $name . " and " . $Name;
Sam and Tina
A typo in a variable’s capital letter is a real bug, because PHP treats it as a brand-new variable.
<?php
$total = 100;
echo $Total;
Warning: Undefined variable $Total in /path/to/index.php on line 3
Function and keyword names are not
PHP does not care about case for built-in function names, class names or keywords such as echo and if.
<?php
ECHO strtoupper("hello");
echo STRTOLOWER("WORLD");
HELLOworld
This works, but nobody writes code this way. Always use the standard lowercase style so the code stays readable.
Constants are case-sensitive
Constants such as PHP_VERSION or your own MAX_SIZE are case-sensitive. By habit, we write them in capitals.
Quick summary
| Thing | Case-sensitive? |
|---|---|
| Variables | Yes |
| Constants | Yes |
| Array keys | Yes |
| Function names | No |
| Class names | No |
Keywords (echo, if, foreach) | No |
Pick one naming style
camelCase for variables and functions, PascalCase for classes and UPPER_CASE for constants. A steady style removes most case typos.