PHP对象3: public / private / protected
<?php /* public 可继承, 内外可访问 private 不可, 只内部访问 protected 可继承, 只内部 */ class A{ protected $name; private function say(){ echo 'Hello, My\'s A<br />'; } public function wsay(){ $this->say(); } } class B extends A { public function Bsay($input){ $this->name = $input; echo 'Say name\'s:'.$this->name.'<br />'; } } $A = new A(); #$A->say(); 只可内部 $A->wsay(); $B = new B(); $B->wsay(); $B->Bsay('B');