下划线并不意味着该变量是私有的。没有必要使用下划线。它只是一个命名约定,提醒开发人员变量/属性/方法是私有的还是受保护的
例如
// This variable is not available outside of the class
private $_someVariable;
class MyClass {
// This method is only available from within this class, or
// any others that inherit from it.
protected function __myFunction() {}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,下划线不是使变量或方法私有的原因;private/protected 关键字就是这样做的。