日期:2011-06-29 浏览次数:20443 次
class Person{ private $name; private $age; private $sex; function __construct($name="",$age=20,$sex="male"){ $this->name=$name; $this->age=$age; $this->sex=$sex; } function getPro($name){ return $this->$name; } function setAge($age){ if($age>100$age<0){ return; } $this->age=$age; } function getAge(){ if($this->age<30){ return $this->age; }elseif($this->age<40){ return $this->age-5; }elseif($this->age<50){ return $this->age-10; }else{ return $this->age-15; } } function say(){ echo "我的名字是:".$this->name.",年龄是:".$this->age.",性别是:".$this->sex.'<br>'; } function __destruct(){ echo $this->name.",再见"."<br>"; } } $p1=new Person("rayhooo",26,"male"); $p1->say(); echo $p1->getPro("name").'<br>'; $p1->setAge(45); echo $p1->getAge().'<br>';