[dev] Coding Standard: Underscores for private method and property names
Ralf Lang
lang at b1-systems.de
Mon Oct 1 08:04:38 UTC 2018
Hallo,
our current wording of the Coding Standard leaves room for
interpretation with regard to underscores in property/method names.
Historically, we used underscores to designate internal/private methods
and properties in classes.
Now, citing
https://github.com/horde/base/blame/master/doc/CODING_STANDARDS.rst
Basics
======
Horde Coding Standards are following PSR-0, PSR-1 and PSR-2 of the `PHP
Framework Interop Group`_
.. _`PHP Framework Interop Group`: http://www.php-fig.org/
PSR-2 suggests under 4.2
Property names SHOULD NOT be prefixed with a single underscore to indicate
protected or private visibility.
and under 4.3
Method names SHOULD NOT be prefixed with a single underscore to indicate
protected or private visibility.
However, Horde Coding Standards suggest
6
Functions used only in the current script/class (e.g. private or
protected) should begin with a _ character (e.g. _exampleLibrary). This
helps distinguish these private functions from other, publicly available
functions.
21 Private Variables
Variables used exclusively within a class should begin with a underscore
('_') character. An example class variable definition: protected
$_variablename;
Both documents use SHOULD (soft requirement wording), though in a
contradicting way.
How to interpret?
a) Explicit statements in the CODING_STANDARDS document override PSR-2,
Horde uses underscores for private/protected -> Should be clarified in
wording
b) Old code uses underscores for private/protected, new code avoids them
-> Should be clarified in wording
Regards
Ralf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pEpkey.asc
Type: application/pgp-keys
Size: 3959 bytes
Desc: not available
URL: <https://lists.horde.org/archives/dev/attachments/20181001/27764b1d/attachment.bin>
More information about the dev
mailing list