php - 下划线方法前缀

标签 php naming-conventions

我一直在检查 CodeIgniter 和 CakePHP 的代码,我注意到它们类中的一些方法带有下划线 _ 或双下划线 __ 前缀.

这样做的目的是什么?

最佳答案

在不属于PHP's magic methods的情况下, 表示Visibility缺少适当的可见性关键字:

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.

关于php - 下划线方法前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3758611/

相关文章:

visual-studio - 命名事件处理程序 : How to make the first letter uppercase

visual-studio - Visual Studio 解决方案和项目的命名约定

java - 在 Java 中命名重载的单元测试方法

php - 如何合并两个关联数组,同时保留它们的键?

php - 如何确定 while 循环是否从 php 中的 db 返回任何内容?

php - 单选按钮不返回第一个值

php - return 语句语法错误

python - simplely __ double underscore as a variable name 是什么意思? Just __ not follow another chars

python - 使用内置函数名称作为属性或方法标识符是不好的做法吗?

php - date() 和 gmdate() 的不同结果