今天复习php面向对象编程,写个简单的小例子~~
一个简单的类:
<?php
class Person{
private $name;
private $weight;
private $height;
function __construct($name,$weight,$height){
$this->name=$name;
$this->weight=$weight;
$this->height=$height;
}
function sport(){
echo "身高".$this->height."体重".$this->weight."的".$this->name."like sport!!";
}
}
?>
创建一个对象:
<?php
include("xiaxie.php");
$p=new Person("张三","75kg","177cm");
$p->sport();
?>