30

I am from Java background. In Java, every method has case-sensitive while calling. But in PHP, I didn't see the case-sensitive function name while calling the functions.

class Sample {

    ...
    ...

    function sampleFunction() {

       ....
       ....

    }

}

$obj = new Sample();
$obj->sampleFunction(); /* Proper call with function name */
$obj->samplefunction(); /* It should show undefined function error but it also calls sampleFunction()  */

Can anyone clear my doubt why this is also called even non-case sensitive function name. And please give me how to restrict in PHP?

Thanks in advance.

Ahmet Kakıcı
  • 6,294
  • 4
  • 37
  • 49
kpmDev
  • 1,330
  • 1
  • 10
  • 28
  • 2
    I don't think you can force case sensitivity beyond good coding practices from your side. This is just another one of PHP's retarded "features" – Bojangles Dec 03 '13 at 07:12
  • They're [not case-sensitive](http://www.php.net/manual/en/functions.user-defined.php). And that's just how the language was designed. You can always use a different language though. – mario Dec 03 '13 at 07:14
  • 4
    Is this question still regarded as off topic? It has a clear answer. Not that it needs more answers though. – JoeMoe1984 Jun 09 '17 at 17:40

2 Answers2

48

They are case insensitive, see this:

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

http://www.php.net/manual/en/functions.user-defined.php

Fibericon
  • 5,684
  • 12
  • 37
  • 64
Anas
  • 576
  • 5
  • 10
  • 3
    +1, for bringing in the content from the manual. – Shankar Narayana Damodaran Dec 03 '13 at 07:16
  • 1
    This is the accepted answer but it says, "any user defined function i think is case sensitive" when the correct answer is that function names are case _insensitive_. – crantok Feb 04 '16 at 15:47
  • 3
    This question is currently the top hit on Google for "php function case sensitive", and the accepted answer (when I came here) incorrectly said that it's case sensitive. I've submitted an edit to correct that. – Soron Feb 25 '16 at 06:45
15

Functions are not case sensitive, Variables are case sensitive.

you can read more info from manual :

http://fr.php.net/manual/en/functions.user-defined.php

Pankaj Pareek
  • 3,806
  • 2
  • 31
  • 42