- 论坛徽章:
- 0
|
本帖最后由 yzhkpli 于 2017-04-24 13:37 编辑
<?php
/*
http://localhost/learnphp_oop/x.class.php
*/
class Person{
private $name='';
private $birth='';
private $gender='';
public function __construct($name,$birth,$gender="male"){
$this->name=$name;
$this->birth=$birth;
$this->gender=$gender;
}
}
class Stu extends Person{
private $school="";
private $name='';
private $birth='';
private $gender='';
public function __construct($name,$birth,$gender,$school){
parent::__construct($name,$birth,$gender);
$this->school=$school;//$this->name="tttt";
}
public function xx(){
//var_dump($this->name);
echo "该学生姓名为 :".$this->name.";该生出生年月".$this->birth.";该生性别为: ".$this->birth.";该生就读学校为: ".$this->school."<br />";
}
}
$t1=new Stu('yuyu','200001','female','BeiJing University');
$t1->xx();//为啥对象里面的 变量都没有 初始化成功 ?
?>
|
|