能見度
在一個類的所有函數和變量的定義,無論是公眾,保護或私人。
公眾
公共交通工具,內部和外部的類是可見的變量或函數。
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秒