PHP 7.0.0 RC 2 Released


要写出能经受住时间考验的代码,建议给任何进入全局命名空间的符号都加上一个不常见的 3-4 字母的前缀(或后缀),中间用下划线分开。为了避免与其它用户空间代码出现命名空间冲突,建议先研究一下其它项目中已有的前缀(或后缀)并适当地公布出来。示例如下:

  • MyPx_someFunc()

  • Foo_Date

  • $asdf_dbh

add a note add a note

User Contributed Notes 4 notes

willian at gt44 dot com
2 years ago
I don't think it makes sense nowadays. We have namespaces now!
kanone at rogers dot com
1 year ago
The javascript community has developed a strong cultural bias against adding anything to the global namespace.  (See e.g. Addy Osmani's article on Essential JavaScript Namespacing Patterns .)  Namespaces have been available in JS for many years and are ubiquitous.  There is also a great deal of freely available tutorial material for the interested reader.
mestresan AT gmail DOT com
11 months ago
Even though nowadays we do have namespaces, for the cases in which the user chooses to not use namespaces theses tips should be followed.
earnie at users dot sourceforge dot net
1 year ago
@willian at gt44 dot com: What about clashes of the namespace?  It is still good advice to check for previously used names before assigning anything to the global namespace.
To Top