首页 > 代码库 > php面向对象继承的初步使用

php面向对象继承的初步使用

<?php
/**
* Created by PhpStorm.
* User: fu
* Date: 2017/7/13
* Time: 13:34
*/

class Person{

public $name;
public $age;

public function __construct($name, $age)
{
$this->name = $name;
$this->age = $age;
}

public function desc(){

}
public function introduce(){
echo ‘姓名:‘.$this->name.‘,年龄:‘.$this->age;
$this->desc();
}
}

class Man extends Person{

public function desc(){
echo ‘,男性有胡子<br>‘;
}

}
class Woman extends Person{

public function desc(){
echo ‘,女生喜欢购物<br>‘;
}
}

$person = new Man(‘李四‘, 25);
$person->introduce();

$person = new Woman(‘丽丽‘, 28);
$person->introduce();

 

php面向对象继承的初步使用