Are PHP functions case sensitive? Are PHP functions case sensitive? php php

Are PHP functions case sensitive?


I am quoting from this:

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

So, its looks like user-defined functions are not case-sensitive, there was a vote for making functions/objects under PHP5 case-sensitive.


No.

PHP functions are not case sensitive.


TL;DR: class names are case-insensitive, but use always the same case as in the declaration (same as with functions). Also, instantiating classes with different case as they were defined may cause problems with autoloaders.


Also, class names are case-insensitive:

<?phpclass SomeThing {  public $x = 'foo';}$a = new SomeThing();$b = new something();$c = new sOmEtHING();var_dump($a, $b, $c);

This outputs:

class SomeThing#1 (1) {  public $x =>  string(3) "foo"}class SomeThing#2 (1) {  public $x =>  string(3) "foo"}class SomeThing#3 (1) {  public $x =>  string(3) "foo"}

Problem is using autoloaders and case-sensitive file-systems (like ext2/3/4), in that you must call the class name with the same case the file containing the class is named (not how the class name is actually cased), or use strtolower:

The class file:

<?php// filename something.phpclass SomeThing {   ...}

The autoloader function (__autoload or a function to register with spl_autoload_register)

function my_autloader($className) {  $filename = CLASSES_DIR . DIRECTORY_SEPARATOR . $className . '.php';  if (file_exists($filename)) {    require($filename);  }}

Now with this code:

$a = new something(); // works$b = new SomeThing(); // does not work$c = new SOMETHING(); // does not work

You may made this work (ie. having effectively case insensitive class names using an autoloader) if you added a call to strtolower() in the autoloader code, but as with functions, is just better to reference a class in the same way as it is declared, have the filename with the same case as the class name, use autoloaders, and forget using strtolower and the likes.