PHP Velho Oeste 2024

ルール

以下のリストは、PHP プロジェクトで新たな内部識別子を作成する際に どのような基準で名前を決めているのかを おおまかにまとめたものです。完全な規約は、公式の » コーディング規約 を参照ください。

  • PHP はトップレベルの名前空間を所有していますが、 きちんとしたわかりやすい名前をつけるようにこころがけ、 衝突が起こらないようにしています。

  • 関数名では、単語の間にアンダースコアを使用します。クラスの場合は、 キャメルケース (camelCase) 形式や パスカルケース (PascalCase) 形式を使います。

  • PHP の拡張モジュールのグローバルシンボルには、 その拡張モジュールの名前を先頭につけます (過去には、この原則を守っていない例が大量にありました)。 たとえば次のようになります。

  • しかし、イテレータや例外については、単純に最後に "Iterator" および "Exception" を追加するようにします。例えば次のようになります。

  • PHP では、__ で始まるシンボルを特殊なものとして予約済みです。 以下にあげるような文書化されている機能を使用する場合を除き、 __ で始まるシンボルを作成しないことを推奨します。

add a note add a note

User Contributed Notes 1 note

up
1
Anonymous
3 years ago
#### Rules for PHP identifiers

1. A variable starts with the $ sign, followed by the name of the variable.

2. A variable name must start with a letter or the underscore character.

3. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).

4. Identifiers are case sensitive. Therefore, a variable named $unicorn is different from a variable named $Unicorn, $uNicOrn, or $unicorN.

5. Identifiers can be any length.

6. An identifier name can’t be identical to any of PHP’s predefined keywords.
To Top