Coder Perfect

Why are PHP methods and functions case-insensitive?

Problem

As shown in the following example, PHP functions and methods are case-insensitive.

function ag()
{
    echo '2';
}

Ag();
class test {
    function clMe()
    {
        echo 'hi';
    }
}

$instance = new test;
$instance->clme();

However, this is not the case with variables. What’s the reasoning behind it?

Asked by user198729

Solution #1

Let me cite Rasmus Lerdorf, the creator of PHP, from an interview.

I heard somewhere that he picked case insensitive function names in PHP since all of the functions introduced felt essentially like tags in an HTML text, and since HTML tags were case insensitive. This characteristic was later retained in the language.

Answered by Shailesh Kumar

Solution #2

Yes, the names of functions and methods are not case-sensitive.

Variable names are case-sensitive, to be sure.

I’m not sure why, other that it’s been that way for a long time and will continue to be that way for backward compatibility concerns.

A couple of links / quotes to various pages of the manual as a reference:

For functions (quoting):

And, when it comes to PHP 4 and backward compatibility, methods aren’t much more than functions in objects.

Also (quoting) for variables:

And object properties are essentially the same as variables in objects — the same can be said about PHP 4 and backward compatibility.

Answered by Pascal MARTIN

Post is based on https://stackoverflow.com/questions/2749781/why-are-functions-and-methods-in-php-case-insensitive