Note that as of mbstring.c version 1.142.2.31, first released as PHP 4.3.4RC3, “auto” has changed meaning. It used to be configured based on #defines, so it was set at compile time, so for precompiled binary users (esp. Windows users) it has always been the same (Japanese mode). However, it is now based on the language that mbstring is configured for at runtime. (setlocale() doesn’t affect this though) Running on English Windows at least, mbstring defaults to a “neutral” mode which results in an “auto” list of “ASCII, UTF-8”. So, the point is, for PHP 4.3.4 or newer, you probably want to either use mb_language(“Japanese”) followed by mb_detect_order(“auto”), or just hardcode your detect order with mb_detect_order(“ASCII, JIS, UTF-8, EUC-JP, SJIS”). (Also note that mb_language() alone won’t do it, you’ll have to set the detect order to “auto” _after_ calling mb_language().)

The problem is very clear: I didn’t apply any encoding_list to mb_detect_order() so the functions is using default neutral mode(which only detects ASCII and UTF-8) to run all tests. Technically the test string ‘abc中文’ contains characters more that ASCII, so the function returns ‘UTF-8’.