In fact, you need to follow a convention, which you already know. The convention can change according to the technology, so if you are programming in PHP can be one, and in Javascript can be another, this is normal because each language has its peculiarities.
One can joke that in PHP the convention is not to follow convention, after all a lot in the library itself and language do not follow. Of course that’s bad, just because the language is bad doesn’t mean you should follow it.
There are even programmers who create auxiliary functions with the "right" convention to use in place of the PHP function that does not follow the convention. Few do, most because they do not think about it, do not know how to do or some who think it is not worth the effort to make and maintain the performance that gives a little more work and requires knowledge beyond PHP.
It gets worse among the various frameworks available:
Phpproject |
Classes |
Methods |
Properties |
Functions |
Variables |
Akelosframework |
Pascalcase |
camelCase |
camelCase |
lower_case |
lower_case |
Cakephpframework |
Pascalcase |
camelCase |
camelCase |
camelCase |
camelCase |
Codeigniterframework |
Proper_case |
lower_case |
lower_case |
lower_case |
lower_case |
Concrete5cms |
Pascalcase |
camelCase |
camelCase |
lower_case |
lower_case |
Doctrineorm |
Pascalcase |
camelCase |
camelCase |
camelCase |
camelCase |
Drupalcms |
Pascalcase |
camelCase |
camelCase |
lower_case |
lower_case |
Joomlacms |
Pascalcase |
camelCase |
camelCase |
camelCase |
camelCase |
modxCMS |
Pascalcase |
camelCase |
camelCase |
camelCase |
lower_case |
Pearframework |
Pascalcase |
camelCase |
camelCase |
|
|
Pradoframework |
Pascalcase |
camelCase |
Pascal/Camel |
|
lower_case |
Simplepierss |
Pascalcase |
lower_case |
lower_case |
lower_case |
lower_case |
Symfonyframework |
Pascalcase |
camelCase |
camelCase |
camelCase |
camelCase |
Wordpresscms |
|
|
|
lower_case |
lower_case |
Zendframework |
Pascalcase |
camelCase |
camelCase |
camelCase |
camelCase |
Source.
Something official.
The important thing is to choose one and follow. No one can say which one is best for you.
I like NomePessoa()
. In PHP not so much. What I see more is the use of nome_pessoa()
. But if it’s method, then it switches to nomePessoa()
.
In JS it is more common nomePessoa()
.
Convention for JS, perhaps the greatest language guru. And the mozilla convention. And yet the google convention.
Just note that jQuery is not a programming language then there doesn’t have to be convention for it but for the JS.
Can explain the
-1
? I think this question is very important and I would like to know why others do not think.– Sergio
Related: How far should I follow the conventions, where I can apply specific style patterns? and Is there any nomenclature for variables defined by underline/underscore?
– rray
A similar question has already been asked for Java (not a duplicate): https://answall.com/q/153540/132 - Certainly, some of what is there (but not everything) applies here.
– Victor Stafusa