21,887
社区成员
发帖
与我相关
我的任务
分享
class Person {
private $name;
private $age;
private $sex;
function __construct($name="", $age=0, $sex="男"){
$this->name=$name;
$this->age=$age;
$this->sex=$sex;
}
private function __get($proName){
if($proName=="age"){
if($this->age>40)
return $this->age-10;
}
return $this->$proName;
}
private function __set($proName, $proValue){
if($proName=="age"){
if($proValue > 100 || $proValue < 0)
return;
}
$this->$proName=$proValue;
}
function say(){
echo "我的名子:{$this->name},我的年龄:{$this->age},我的性别:{$this->sex}。<br>";
}
function run(){
$this->left();
$this->left();
$this->right();
$this->right();
$this->gogo();
$this->gogo();
$this->gogo();
}
private function left(){
echo "LLLLLLLLLLLLL<br>";
}
private function right(){
echo "RRRRRRRRRRRRRR<br>";
}
private function gogo(){
echo "GGGGGGGGGGGGGGGGG<br>";
}
private function __isset($proName){
if($proName=="age")
return false;
return isset($this->$proName);
}
private function __unset($proName){
unset($this->$proName);
}
function eat(){
}
function __destruct(){
echo $this->name."再见!<br>";
}
}
$p1=new Person("zhangsan", 80, "女");
$p2=new Person("lisi", 25);
$p3=new Person("wangwu");
unset($p1->name);
if(isset($p1->name)){
echo "存在<br>";
}else{
echo "没有这个成员 <br>";
}