悠悠楠杉
网站页面
public(公有) | protected(受保护) | private(私有) | |
---|---|---|---|
外部 | Y | N | N |
子类中 | Y | Y | N |
本类中 | Y | Y | Y |
<?php
class Human
{
public $money = '3000';
protected $car = 'BMW';
private $gf = 'mv';
public function par()
{
echo $this->money;
echo $this->car;
echo $this->gf;
}
}
class Stu extends Human
{
public function sub()
{
echo $this->money;
echo $this->car;
echo $this->gf;
}
}
$stu = new Stu;
$stu->par();
$stu->sub(); //gf没有被继承
echo $stu->money;
echo $stu->car; //无权限访问
echo $stu->gf; //无权限访问