能见度
在一个类的所有函数和变量的定义,无论是公众,保护或私人。
公众
公共交通工具,内部和外部的类是可见的变量或函数。
PublicClass 类 PublicClass
{
A public variable / /公共变量
name ; $的名称;
A public function / /公共职能
SetName ( $ name )公共职能的setName(名称)
{
this - > name = $ name ; - >名称= $名称;
}
}
保护
保护意味着当前类和类继承这个类的变量或函数是可见的。
ProtectedClass 类 ProtectedClass
{
A protected variable / /受保护的变量
name ;保护美元的名字;
A protected function / /一个保护功能
SetName ( $ name )保护功能的setName( 姓名 )
{
this - > name = $ name ; - >名称= $名称;
}
}
SubClass : ProtectedClass 子类:ProtectedClass
{
__construct ( ) 功能 __建构()
{
I can change the value of the protected variable . / /我可以改变受保护的变量的值。
this - > name = ' New class ' ; - >名称='一类新的';
}
}
私人
私人手段,变量或函数只能在当前类中可见。
PrivateClass 类 PrivateClass
{
A private variable , this cannot be seen outside the class . / /私有变量,这不能被看作类的外部。
name ;私营$名称;
A private function / /私有函数
SetName ( $ name )私有函数的setName( 姓名 )
{
this - > name = $ name ; - >名称= $名称;
}
}
已提供任何意见。
书面由多米尼克·斯金纳
最后更新:2011年10月25日十六点00分38秒