Why are functions and methods in PHP case-insensitive?

user198729 picture user198729 · May 1, 2010 · Viewed 27.6k times · Source

Functions and methods in PHP are case-insensitive as illustrated in the following example.

function ag()
{
    echo '2';
}

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

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

But that's the not case with variables. What's the rationale?

Answer

Shailesh Kumar picture Shailesh Kumar · Jun 10, 2011

Let me quote from Interview – PHP’s Creator, Rasmus Lerdorf

The first version of PHP was a simple set of tools that I put together for my Website and for a couple of projects. One tool did some fancy hit logging to an mSQL database, another acted as a form data interpreter. I ended up with about 30 different little CGI programs written in C before I got sick of it, and combined all of them into a single C library. I then wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library.

The simple parser slowly grew to include conditional tags, then loop tags, functions, etc. At no point did I think I was writing a scripting language. I was simply adding a little bit of functionality to the macro replacement parser. I was still writing all my real business logic in C.

I have read somewhere that since all the functions introduced essentially felt like tags in an HTML document and since HTML tags were case insensitive, he chose function names in PHP to be case insensitive. Later on this feature remained on in the language.