受保護的繼承后可以訪問,私有的只能在該類中訪問,不會被繼承訪問
class Man{
protected $name='lee';//受保護
private $age=123;//私有
function __construct(){
echo $this->name;//lee
echo $this->age;//123
}
}
class Girl extends Man{
function __construct(){
echo $this->name;//lee
echo $this->age;//不會出現123,
}
}
new Man();
new Girl();
<?php
class Man{
protected $name='lee';//受保護
private $age=123;//私有
function __construct(){
echo $this->name;//lee
echo $this->age;//123
}
}
class Girl extends Man{
function __construct(){
echo $this->name;//lee
echo $this->age;//不會出現123,
}
}
new Man();
new Girl();
