请各位帮我看看我的 private $isHungry=true;为什么不提示呢?不是应该访问不到么?
<?php
header("Content-type: text/html; charset=utf-8");
date_default_timezone_set("PRC");
class Human
{
public $name;
public $weight;
//受保护的类成员,只有自身和其子类可以访问到
protected $height;
//也是受保护的成员,只能被自身访问
private $isHungry=true;
public function eat($food)
{
echo $this->name."'s eating ".$food."<br>";
}
}
class NbaPlayer extends Human
{
public $team='';
public $PlayNum='';
//受保护的类成员,只能别自身访问到,当public function getAge()自身定义了这个方法时,就可以被自身访问到
private $age='50';
function __construct($name,$height,$weight,$team,$PlayNum)
{
echo"construct方法被调用<br>";
$this->name=$name;
$this->height=$height;
$this->weight=$weight;
$this->team=$team;
$this->PlayNum=$PlayNum;
echo $this->isHungry."\n";
}
function __destruct()
{ echo"destruct方法被调用.$this->name.<br>";
}
//定义方法[跟原来定义函数是一样的]
public function run()
{
echo'Running<br>';
}
public function jump()
{
echo'Jumping<br>';
}
//受保护的类成员age可以被自身调用
public function getAge()
{
echo $this->name."'is age is ".($this->age)."\n";
}
}
$wang=new NbaPlayer("wang","160cm","50kg","Bull","56");
//echo $wang->getAge()."\n";
//echo $wang->height;//提示不能访问
?>