public 公共的 谁都可以用,也可以修改
protected 受保护的 只有自己和后代可以使用和修改
private 私有的 只有自己可以使用和修改
eg:
class MyTest{ public $name; protected $sex; private $birth; public function __construct($name,$sex,$birth){ $this-> name = $name; $this-> sex = $sex; $this-> birth = $birth; } public function getBirth(){ return $this->birth; } public function setSex($sex){ if($sex==='男'||$sex==='女'){ $this->sex = $sex; }else{ return null; } } } $test = new MyTest('李四','男',time()); echo $test->name; echo $test->getBirth();