Paste_Image.png
<?php
//peoples republic of china
date_default_timezone_set("PRC");
class Human
{
public $name;
public $weight;
protected $height;//只有自身和子类可以访问
private $isHungry = true;//不能被子类访问
public function isHungry()
{
echo $this->name . " is Hungry? " . $this->isHungry;
}
}
class NbaPlayer extends Human
{
public $team = "Bull";
public $playerNumber = "23";
private $age = 40;
function __construct($name, $height)
{
$this->name = $name;//this 伪变量
$this->height = $height;
}
public function getAge()
{
echo $this->name . "'s age is " . ($this->age - 2);
}
}
$jordan = new NbaPlayer('hehe', '220cm');
$jordan->getAge();
echo "<br/>";
$jordan->isHungry();
//echo "<br/>".$jordan.$height;//无法访问
?>
Paste_Image.png