Underscore method prefix

后端 未结 7 2035
挽巷
挽巷 2021-01-06 00:12

I\'ve been examining the code of CodeIgniter and CakePHP and I noticed that some of the methods in their classes are prefixed with an underscore _ or a double u

7条回答
  •  清酒与你
    2021-01-06 00:37

    In the case where it is not any of PHP's magic methods, it is to indicate Visibility in lack of proper Visibility keywords:

    Cake Coding Conventions:

    As we cannot use PHP5's private and protected keywords for methods or variables, we agree on following rules:

    • A protected method or variable name start with a single underscore ("_").
    • A private method or variable name start with double underscore ("__").

    CodeIgniter conventions:

    Methods and variables that are only accessed internally by your class, such as utility and helper functions that your public methods use for code abstraction, should be prefixed with an underscore.

提交回复
热议问题