我在父类中定义了,$height私有属性,但是还能在外边被访问到
<?php
class Human{
public $name ;
private $height ;
protected $weight;
private $ishungry=true;
public function eat($food){
echo $this->name."'s eating ".$food."\n";}
public function info(){
echo "hunman:".$this->name.";".$this->height.";".
$this->ishungry."\n";
}
}
class NbaPlayer extends Human{
private $age="40";
function __construct($name,$height,$weight,$team,$playernumber){
echo "in nbaplayer construct\n";
$this->name=$name;
$this->height=$height;
$this->weight=$weight;
$this->team=$team;
$this->playnumber=$playernumber;
echo $this->height."\n";
echo $this->weight."\n";
//设置为私有属性但是外部可以调用private $height ;
}
//定义方法
public function run(){
echo "Running\n";
}
public function jump(){
echo "Jumping\n";
}
public function dribble(){
echo "Dribbling\n";
}
public function shoot(){
echo "Shooting\n";
}
public function dunk(){
echo "Dunking\n";
}
public function pass(){
echo "passing\n";
}
public function getage(){
echo $this->name."'s age is".($this->age-5);
}
}
$jordan= new NbaPlayer('jordan','198cm','98kg','bull','23');
echo $jordan->height."</br>";
//echo $jordan->weight."</br>";
echo $jordan->ishungry."</br>";
?>