Home > PHP > Case Sensitivity in PHP function names

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.

About these ads
Categories: PHP
  1. The Craw
    July 29, 2012 at 7:52 pm

    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. :)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: