Case Sensitivity in PHP function names
People from non PHP background will be confused a bit about PHP function’s case insensitivity while calling them from the PHP code. You can call the function name in any case (note that the name should be same) it will not trigger any error like we have in other languages like C++, JavaScript, etc
<?php
function foo() {
echo "in foo<br>";
}
foo();
fOo();
FOO();
foO();
?>
All the above function calls will invoke the function foo without any issues. But personally I’d prefer to use a function name that matches with the function definition in the code to avoid any confusions in the future.
Categories: PHP
Honestly, as much as I love PHP, I think this is one of its weaknesses. Having inconsistencies like this in any language can make it confusing for newbies. For instance, as you said, function names are not case sensitive, so “testFunction” is the same as “testfunction” However, variable names are case sensitive, so if you have this:
$testvar = ‘some output’;
echo $TestVar;
It will output an error “Notice: Undefined variable: TestVar in {file path} on line line 2″
This is a useful post. Thank you for sharing.