<?php
class Person{
var $name;
var $sex;
var $age;
var $height;
var $weight;
var $birthday;
function __construct($name,$sex,$age,$height,$weight,$birthday){
$this-> name=$name;
$this-> sex=$sex;
$this->age=$age;
$this->height=$height;
$this->weight=$weight;
$this->birthday=$birthday;
}
function desc(){
echo '姓名' . $this->name .',性别' . $this->sex .',年龄' . $this->age .',身高' .$this->height .',体重' .$this->weight .',出生年月' .$this->birthday;
}
}
$p= new Person("王二麻子","男",17,176.5,73.5,"1997/9/23");
$p->desc();
?>
输出的结果
姓名王二麻子,性别男,年龄17,身高176.5,体重73.5,出生年月1997/9/23
<?php
class Dog{
var $name;
var $sex;
var $color;
var $type;
var $weight;
var $sHeight;
var $price;
function __construct($in_name,$in_sex,$in_color,$in_type,$in_weight,$in_sHeight,$in_price){
$this-> name=$in_name;
$this-> sex=$in_sex;
$this->color=$in_color;
$this->type=$in_type;
$this->weight=$in_weight;
$this->sHeight=$in_sHeight;
$this->price=$in_price;
}
function show(){
echo '姓名' . $this->name .',性别' . $this->sex .',颜色' . $this->color .',肩高' .$this->sHeight .',体重' .$this->weight .',价格' .$this->price;
}
}
$b= new Dog("阿八","母","棕红","泰迪",5.2,26,2000);
$b->show();
?>
输出的结果
姓名阿八,性别母,颜色棕红,肩高26,体重5.2,价格2000
<?php
class Square{
var $length;
var $width;
function __construct($in_length,$in_width){
$this-> length=$in_length;
$this-> width=$in_width;
}
function calc(){
$acr=$this->length * $this->width;
echo '长' . $this->length .',宽' . $this->width .',面积' . $acr;
}
}
$s= new Square(6,5);
$s->Calc();
?>
输出结果
长6,宽5,面积30