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 static $sValue = "sValue";
public function isHungry()
{
echo $this->name . " is Hungry? " . $this->isHungry;
}
}
class NbaPlayer extends Human
{
public $team = "Bull";
public $playerNumber = "23";
private $age = 40;
static public $president = "David Stern";
static public function changePresident($newPresdt)
{
self::$president = $newPresdt;
echo "parent sValue" . parent::$sValue . "<br/>";
}
function __construct($name, $height)
{
$this->name = $name;//this 伪变量
$this->height = $height;
}
public function getAge()
{
echo $this->name . "'s age is " . ($this->age - 2);
}
}
echo NbaPlayer::$president . '<br/>';
NbaPlayer::changePresident('changepre');
echo NbaPlayer::$president . "<br/>";
echo Human::$sValue;
?>
Paste_Image.png
Paste_Image.png