[dev] Coding Standard: Underscores for private method and property names

Jan Schneider jan at horde.org
Thu Oct 4 14:59:18 UTC 2018


Zitat von Ralf Lang <lang at b1-systems.de>:

> 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

That.

> b) Old code uses underscores for private/protected, new code avoids them
> -> Should be clarified in wording
>
>
> Regards
>
> Ralf



-- 
Jan Schneider
The Horde Project
https://www.horde.org/



More information about the dev mailing list