1.public (公开的)
2.private (私有的)
3.protected(受保护的)
1.public
<?php
class test{
public $name;
}
$stu=new test();
$stu->name="0ne";
echo $stu->name; //可以外部来操作属性
?>
2.private
通过公有的方法 对私有的属性来进行赋值
好处在于 可以控制用户的输入
<?php
class test{
private $name;
function setUserInfo($name){
if($name == ''){
echo "姓名不能为空";
exit;
}
$this->name=$name;
}
function getUserInfo(){
echo "姓名 :".$this->name."<br>";
}
}
$stu=new test;
$stu->setUserInfo('');
$stu->getUserInfo();
$stu2=new test;
$stu2->setUserInfo('0ne');
$stu->getUserInfo();
?>
3.protected
在整个继承链上访问