PHP Velho Oeste 2024

规则

以下列表指出了 PHP 工程在选择新的内部标识符时保留给自己的权利。最终指南是官方的» 编码标准

  • PHP 拥有最顶层命名空间,但是会尝试找到合体的描述命名以避免任何明显的冲突。

  • 函数名在两个词中间使用下划线,类名则同时使用 camelCasePascalCase 规则。

  • PHP 在任何扩展库的全局符号前附加上扩展库的名称(此规则在过去则有无数例外)。例如:

  • Iterators 和 Exceptions 则只是简单加上 "Iterator" 和 "Exception" 后缀。例如:

  • PHP 保留所有以 __ 开头的符号作为魔术符号。建议用户不要在 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