International PHP Conference 2015

Dicas

Para escrever código que não sofrerá problemas no futuro, é recomendado prefixar (ou sufixar) qualquer coisa que vá para o escopo global com um prefixo (ou sufixo) incomum de 3 a 4 letras, separados por um sublinhado (_). É recomendado que, para evitar conflitos de namespace com outros códigos existentes, o projeto pesquise prefixos existentes (ou sufixos) usados em outros projetos e anunciem o prefixo (ou sufixo) escolhido adequadamente. Exemplos:

  • MyPx_someFunc()

  • Foo_Date

  • $asdf_dbh

add a note add a note

User Contributed Notes 4 notes

up
20
willian at gt44 dot com
2 years ago
I don't think it makes sense nowadays. We have namespaces now!
up
3
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.
up
1
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.
up
1
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