定义一个类,并且声明一个对象。
类外调用函数。
<?php
class cat{
var $height;
var $weight;
var $name;
var $age;
var $sex;
function eat(){
echo $this ->name." are eating.";
}
function play(){
echo $this ->name." are playing.";
}
function H(){
echo this−>height.this ->height.this−>height.this ->name." is 20cm.";
}
function W(){
echo this−>weight.this ->weight.this−>weight.this ->name." is 2kg."
}
}
$animal = new cat();
$animal ->name = “key”;
$animal -> eat();
echo “\n”;
$animal -> H();
echo “\n”;
$animal -> W();
echo “\n”;
?>
玩转PHP(三)
最新推荐文章于 2025-03-07 21:17:45 发布