downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ルール> <パーサトークンの一覧
[edit] Last updated: Mon, 01 Nov 2010

view this page in

付録 R. ユーザレベルでの命名の手引き

これは、あなたが書く PHP コード中の識別子によりよい名前をつけるための手引きです。 グローバル名前空間のシンボルを作成するコードでシンボルの名前を決める際には、 以下のガイドラインを考慮することが重要です。これにより、 PHP の将来のバージョンとの衝突を避けることができます。

グローバル名前空間

グローバル名前空間に属する言語構造には、このようなものがあります。

  • 関数

  • クラス

  • インターフェイス

  • 定数 (クラス定数以外)

  • 関数/メソッド の外部で定義された変数



add a note add a note User Contributed Notes ユーザレベルでの命名の手引き
clancy hood at gmail dot com 11-Apr-2009 10:15
The specified permitted characters in variable names (including the first character) are somewhat more permissive than you might expect.
 
The specified regex is [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* (from ./functions.user-defined.php)

On running the following you can see those outside of [a-zA-Z0-9_] that work. Your browser/shell may not display all properly, and some editors (I tested in Textmate) may simply remove things it doesn't grok as whitespace.  However, there are some pretty sexy characters in there should you be looking for a unique namespace which is not too lengthy.  Using them can be inconvenient for others who may not have a suitable keyboard for single-stroke entry (mine is Spanish). Best used for a program's internally relevant methods - which are those we wish least to pollute a namespace.
 
<?php

    header
('Content-type:text/plain; charset=utf-8');

    function
unichr($u) {
        return
mb_convert_encoding('&#'.intval($u).';', 'UTF-8', 'HTML-ENTITIES');
    }

    for(
$i = hexdec("7f"); $i <= hexdec("ff"); $i++) echo unichr($i)."\n";
   
   
// simple example

   
function ñ(){
        echo
"I'm ok!";
    }
   
   
ñ();

?>

 
show source | credits | sitemap | contact | advertising | mirror sites