1.public (公开的)
2.private (私有的)
3.protected(受保护的)

1.public

  1. <?php
  2. class test{
  3. public $name;
  4. }
  5. $stu=new test();
  6. $stu->name="0ne";
  7. echo $stu->name; //可以外部来操作属性
  8. ?>

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

在整个继承链上访问
image.png