Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

php

I use many functions in my PHP codes like these; UID(), user_getProfileImage() ... etc. I'm writing all my projects on Windows and working well. It's OK up here but when I put my project on my server it's giving error like this;

Fatal error: Call to undefined function UID() in /var/www/vhosts/...

What? Is it undefined?!

I'm checking all my project files and FTP'ing all files to server again, again... And same error.

But when I change the name of UID() to uid() (both in lib.php and other places that where it's used), it's working well.

So what's the problem? What's the matter with this server?

Local PHP vers: 5.3.10

Server PHP info: http://... removed

Note: I'm encoding all PHP files in "UTF-8 without BOM" (as always) with Notepad++, and interestingly the other project is working well even use same functions and run on the same server.

Thanks.

/##############################/

UPDATE (and solution);

  1. Do not use "I" (capital "i") character in any function name or
  2. Simply use setlocale like this; setlocale(LC_TIME, "tr_TR.UTF-8") // I need just locale time config and used this
  3. If you need LC_ALL, do not forget set back LC_CTYPE in en_US, i.e:

    setlocale(LC_ALL, "tr_TR.UTF-8"); setlocale(LC_CTYPE, "en_US");

like image 374
K-Gun Avatar asked Jan 29 '26 12:01

K-Gun


2 Answers

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.

like image 150
salathe Avatar answered Jan 31 '26 02:01

salathe


It’s actually known bug, yet still not fixed since 2002! See #18556.

In short, PHP uses internal tolower() function, which is locale-aware, but in Turkish there are some specific rules for I (undotted ı is the lowercase of I, and the dotted İ is the uppercase of i). So if you have class name of method name having upper I (newInstanceArgs, Image, etc), you’re affected.

The only workaround for now seems to be setting LC_CTYPE to some working locale, eg.

setlocale(LC_ALL, 'tr_TR');
setlocale(LC_CTYPE, 'en_US');
like image 35
sobstel Avatar answered Jan 31 '26 03:01

sobstel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!