我一直在检查 CodeIgniter 和 CakePHP 的代码,我注意到它们类中的一些方法带有下划线 _
或双下划线 __
前缀.
这样做的目的是什么?
最佳答案
在不属于PHP's magic methods的情况下, 表示Visibility缺少适当的可见性关键字:
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 ("__").
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.
关于php - 下划线方法前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3758611/