文字
分享

规则

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

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

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

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

    • curl_close()

    • mysql_query()

    • PREG_SPLIT_DELIM_CAPTURE

    • new DOMDocument()

    • strpos() (以前的一个失误例子)

    • new SplFileObject()

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

    • ArrayIterator

    • LogicException

  • PHP 保留所有以 __ 开头的符号作为魔术符号。建议用户不要在 PHP 中创建以 __ 打头的符号,除非是要使用有文档记载的魔术函数功能。例如:

    • __get()

    • __autoload()

用户评论:

[#1] Jon at kexsof dot com [2007-10-22 05:08:51]

Angst relief for Drupal apprentices: 
remember that the prefix (and suffix) for PHP magical symbols 
is two (2) underscores.  The Drupal coding standard is one underscore
for some types of programmer-created identifiers.

上一篇:全局命名空间下一篇:提示