Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are functions and methods in PHP case-insensitive?

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?

like image 808
user198729 Avatar asked May 01 '10 11:05

user198729


People also ask

Are PHP methods case-sensitive?

In PHP, class names as well as function/method names are case-insensitive, but it is considered good practice to them functions as they appear in their declaration.

What is case-insensitive in PHP?

Summary. PHP is partially case-sensitive. PHP constructs, function names, class names are case-insensitive, whereas variables are case-sensitive.

Why is PHP partially case-sensitive?

Indeed, the PHP is not a case sensitive language, but in other hands, it is neither case insensitive language since it is comprised of both, i.e. — PHP is a case sensitive as well as case insensitive language.

Is PHP case-sensitive or case-insensitive?

In PHP, variable and constant names are case sensitive, while function names are not.


1 Answers

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.

like image 111
Shailesh Kumar Avatar answered Oct 16 '22 03:10

Shailesh Kumar