Is PHP a case sensitive language?
Partly. In PHP, variable names are case-sensitive, but function names, class names and keywords are not.
| Case-sensitive | Not case-sensitive |
|---|---|
| Variable names ($name and $Name are different) | Keywords like echo, if, while, function |
| Constants (created with define or const) | Function names (sum() and SUM() are same) |
| Array keys (“Name” and “name” are different) | Class names and method names |
<?php
$name = "James";
ECHO $name . "<br>"; // keywords are not case-sensitive
function sum() {
return "Function called";
}
echo SUM(); // same as sum()
?>
Output:
Tutorials Class - Output Window
James
Function called
If you write echo $NAME;, PHP shows a warning “Undefined variable $NAME”, because it is a different variable.
Note:
Even if PHP allows it, write function and class names in the same case as they were created. It keeps the code clean. See PHP Syntax.
Learn more about the similar topics:
| Tutorials |
|---|
| PHP Variables |