Case Sensitivity
Keywords and function names are case-insensitive, but variable names are case-sensitive.
In PHP, keywords (such as if, echo, while), classes and function names are not case-sensitive.
Variables are different
Variable names are case-sensitive. $color, $Color and $COLOR are three completely different variables.
Example
Loading editor…
Press Run to execute the code.
When to use it
- Avoiding bugs from mistyping a variable name in the wrong case.
- Knowing function and keyword casing is flexible, while variables are strict.
- Understanding why $Name and $name are two different variables.
More examples
Variables ARE case-sensitive
$name and $Name are two distinct variables.
<?php
$name = "lower";
$Name = "upper";
echo $name . " " . $Name;Keywords are NOT case-sensitive
Keywords like echo/if/while may be written in any case — lowercase is conventional.
<?php
ECHO "works ";
Echo "too";Function names ignore case
Built-in function names are case-insensitive, though lowercase is standard style.
<?php
echo STRTOUPPER("hi"); // HI
Discussion