Do You PHP はてブロ

Do You PHPはてなからはてブロに移動しました

PHP and Unicode: A Love at Fifth Sight

shimooka2005-12-15

from ApacheCon US05。Andrei Zmievskiさんのプレゼン。「私は日本語は分からない」と言いつつ、

$str = '検索オプション';
print_r(strlen($str));

という具合にサンプルコードに日本語がバシバシ含まれていた。でも、「検索オプション」という言葉が出るのはやはりyahooの人だからか?

以下、プレゼンの概要メモ。

  • PHP6ネタで、内部エンコーディングUnicodeにしよう、という話
  • 参加人数は20名程度。朝一番(09:00)のセッションだったから?USだったから?
  • 文字セット・エンコーディング
  • Unicode 4.0
  • Goals
    • Native Unicode string type
    • distinct binary type
    • unicode string literals
    • updated language semantics
    • upgrade existing functions, rather than create new ones
    • backwards compatibility
    • making simple things easy and complex things possible
    • focus on functionality
    • parity with java's unicode and i18n ...
  • ICU
    • international components for unicode
  • let there be unicode!
    • a control switch called unicode_sematics
  • new string types
    • Unicode: textual data (UTF-16 internally)
    • Binary: バイナリデータと文字列はバイトレベルで処理される
  • unicode_semantics=onで有効化
  • filename_encoding, stream-specific encodingが追加される
  • script/source encoding
    • iniもしくはdeclare()プラグマで指定可能

declare(encoding="iso-8859-1");
$uni = "al";
include "myfile.php";

  • fallback_encoding
  • encoding変換問題
    • 変換エラー時の動作はcustomizable
  • stream filter

$fp = fopen(..., 'w');
stream_filter_append($fp, 'unicode.to.utf8');
fputs(...);

  • クラス名や変数名にマルチバイト文字が使える
    • 使うのか?
  • 現状ではCVSツリー内のみにある