Are PHP Functions Case Sensitive

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.

PHP & Case Sensitivity

Why is PHP partially case senstive?

I can only speculate that this stems from very early versions, probably PHP/FI 2.0. The manual explicitely states:

Keep in mind that PHP/FI function names are not case sensitive.

Most user input, such as GET and POST parameters, has always been registered as global variables, back then. Treating these as case insensitive would likely have caused issues, and supposedly therefore all variables have been treated as being case sensitive.

From what I can tell these have been the only kinds of identifiers in PHP/FI 2.0. All others have been introduced later, apparently mimicking the case-insensitive function names.

Constants, which are special, have only been introduced as of PHP 4 (the PHP 3 manual mentions "constants", but these are nowadays referred to as "literals"). For some mysterious reason (maybe no consensus could be found), it had been decided to allow constant identifiers to be define()d either case sensitive or insensitive on the developers discression. Interestingly, while define() defaults to case sensitive constants, the respective C counterparts (REGISTER_*_CONSTANT) default to case insensitive.

Is PHP function names case-sensitive or not?

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

Are PHP functions case-sensitive, if not...?

This hints at suffering from "the I problem", which manifests itself when PHP is using a Turkish locale (tr_TR, tr_TR.utf8…). When doing so, the case-insensitive check between uppercase and lowercase letter "i" fails.

See https://bugs.php.net/18556 — "Setting locale to 'tr_TR' lowercases class names"


You have a couple of solutions:

  • Define and call your function with same-cased letters (or, at the very least the letter "i"); upper or lower is not important.
  • Use a locale not affected by this (mis)behaviour.

The latter is preferred, mostly because it's usually a one-tiny-change-fixes-all-problems sort of task.

Forcing case sensitive functions in PHP :: by re-compiling the source?

Finding clues on the net on how exactly to do this seems illusory; however, the following may be useful for anyone looking for clues in achieving something related.

To modify & compile the PHP source-code, see this article:

How to modify the php source code and recompile it?


Here's a few pointers that may be useful:

  • download the PHP source-code from here: http://php.net/downloads.php
  • have a look in the main "engine" folders for files that reference sensitiv & case_ in their contents; however, it is likely in here: ./Zend/zendAPI.c (citation needed)
  • take note of the constant CONST_CS and its value, defined in ./Zend/zend_constants.h file as it is used frequently
  • edit what you see fit, compile the updated code and copy+paste the necessary components into your main PHP runime folder, (in linux it is most likely in: /etc/php


To make your changes be configurable in php.ini

  • you will need to edit the ./Zend/zend_ini.c file
  • add your setting as a function in there
  • make sure it's defined & referenced where necessary, as in the ./Zend/zend_ini_scanner.* files.


To make your changes be configurable in Apache config & .htaccess

  • have a look here on how Apache modules work and how they are made: https://httpd.apache.org/docs/2.4/developer/modguide.html
  • get the mod_php5.c source code that corresponds relatively with the PHP & Apache versions: https://searchcode.com/codesearch/view/2479116/


Question specific

The above may be helpful for re-building PHP, but, there may be a better and much quicker solution.


Constructive criticism

Related to the nature this question specifically, editing & re-compiling the source may be overkill. Not only is it completely out of "PHP language" scope, but mentioning that this is targeted a large audience may defeat the purpose of the framework / boilerplate entirely.


A better approach

The exact reason for why it is so crucial for case-sensitivity of these exact data-type constant words is unknown; however, maybe re-naming them, or defining functions to use in stead of constant comparison could be beneficial, so:

  • instead of the word: List, how about ListDT (for List-Data-Type)
  • comparison may be longer to type than a short function like: isList()

After all: "speed of coding" could be more important than "speed of code" in many cases.

This approach may prevent the need for re-compiling PHP and the "target audience" won't need to manually obtain and install a very specific PHP version just because "the framework" demands some specific words.

String type casing in php, is it string or String?

As PHP is a partially case sensitive language and, in particular, keywords are NOT case sensitive, the case doesn't matter for built-in type names. Both string and String will work as type declaration (aka 'type hint').

The official documentation mentions the lowercase variants, so it's probably a good idea to use lowercase keywords as code style — just like most PHP code styles use foreach and not Foreach, for example.

P.S. You can find the documentation on the PHP Function arguments page, 'Type declarations' section.

Which are case sensitive among php/javascript/html?

HTML is not case-sensitive (XHTML is, though).

PHP respects case in variable names, but not functions.

Javascript is case-sensitive.



Related Topics



Leave a reply



Submit