3

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");

Kerem
  • 11,377
  • 5
  • 59
  • 58

4 Answers4

3

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.

salathe
  • 51,324
  • 12
  • 104
  • 132
  • 1
    Thank you very much. Actually I resolved the problem myself, cos' forgotten where I wrote for help. :) But solution is same with yours. Thank you. – Kerem May 23 '12 at 23:42
1

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');
sobstel
  • 1,432
  • 16
  • 11
  • Thank you, this does fix the issue. You should use the UTF-8 encoding to avoid any weird character outputs `setlocale(LC_CTYPE, 'en_US.UTF-8');` – Ismail Nov 25 '19 at 11:18
0

Why is the project running correctly on Windows (I suppose you have set up a development server - LAMP) and not on the live server?

I suppose that the live server is Apache on a linux distribution, so another check you should do is that the files you "include" in your scripts are the exact file names (I'm saying this, as e.g. if you include "Lib.php" while the name of the file is "lib.php" will not raise any errors in windows and the "lib.php" will be included normally, but in linux (i.e. the live server) include "Lib.php" will not work, as file names are case sensitive.

m1lt0n
  • 361
  • 3
  • 9
0

On Linux file names are case sensitive, so I am guessing that your UID() function lives in a file or folder with a name that is included wrongly. Check the character case of the full path on all your require, require_once, include, include_once statements in all your scripts.

Jannie Theunissen
  • 28,256
  • 21
  • 100
  • 127