定义一个类,并且声明一个对象。
类外调用函数。
<?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
t
h
i
s
−
>
h
e
i
g
h
t
.
this ->height.
this−>height.this ->name." is 20cm.";
}
function W(){
echo
t
h
i
s
−
>
w
e
i
g
h
t
.
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(三)
最新推荐文章于 2022-05-06 17:01:05 发布