As previously stated by William: there is no correct one. There is a recommendation, which is well demonstrated in PSR-2 - an encoding style.
I agree with the part that William explains about "if you start with a pattern, continue with it to the end". But it is important to note here that there are patterns that are employed by most PHP libraries.
If we have to address this library development issue, I strongly recommend using the PSR-2 standards.
It is easy to notice that nowadays, the vast majority of libraries (Zend
, Laravel
, Guzzle
, Gregwar
), use the standard employed by PSR-2
(it deals with other matters, and not only the nomenclature of methods).
I’m not saying that you should do everything these libraries do, but it’s important, in the development of libraries, to maintain a standard, to facilitate users accustomed to the standards employed in libraries to use their.
If you think about how standard PHP classes or interfaces are written, for example, you can use common sense and do something similar, so you can present code closer to the "reality" of the language.
Note for example the interface summary ArrayAccess
:
interface ArrayAccess {
/* Métodos */
abstract public boolean offsetExists ( mixed $offset )
abstract public mixed offsetGet ( mixed $offset )
abstract public void offsetSet ( mixed $offset , mixed $value )
abstract public void offsetUnset ( mixed $offset )
}
Note that the names of the methods are in Camelcase (as explained by Guilherme).
Summary of PSR (for your case)
As a summary of the PSR-2 (which I remember in my head), I can state that the patterns are:
Use camelCase to name the methods of a class.
The words final
or abstract
must come before visibility (public
, protected
or private
) of the methods.
Use snake_case for functions.
Function keys or methods must contain a line break.
Reinforcing again that this is a recommendation, it is not mandatory.
I updated the response and add on the PSR recommendations.
– Guilherme Nascimento
The cleanest thing is to be consistent, one way or another.
– Bacco