<?php
class mao{ //定义猫类
public $age=0; //定义多个属性并初始化
public $weight=50;
public $color='white';
}
$mao1=new mao(); //实例化猫类的多个对象
$mao2=new mao();
//输出mao1、mao2对象的属性
echo "mao1的年龄为{$mao1->age},体重为{$mao1->weight},毛色为{$mao1->color}。<br />";
echo "mao2的年龄为{$mao2->age},体重为{$mao2->weight},毛色为{$mao2->color}。<br />";
?>

109-PHP类成员初始化值-LMLPHP

05-11 22:21