Why are functions and methods in PHP case-insensitive?

PhpSyntaxCase Insensitive

Php Problem Overview


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?

Php Solutions


Solution 1 - Php

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.

Solution 2 - Php

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

And yes, variables names are case-sensitive.

I am not sure there's a reason for that -- except it's been this way for a long time, and, so, remains the case, for backward compatibility reasons.



As a reference, a couple of links / quotes to various pages of the manual:

For functions (quoting):

> Note: Function names are > case-insensitive, though it is usually > good form to call functions as they > appear in their declaration.

And methods are not much more than functions in objects -- especially when we think about PHP 4 and backward-compatibility.


And, for variables (quoting):

> Variables in PHP are represented by a > dollar sign followed by the name of > the variable. The variable name is > case-sensitive.

And object properties are not much more than variables in objects -- same remark about PHP 4 and backward-compatibility.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser198729View Question on Stackoverflow
Solution 1 - PhpShailesh KumarView Answer on Stackoverflow
Solution 2 - PhpPascal MARTINView Answer on Stackoverflow