定义一个类,并且声明一个对象。
类外调用函数。
<?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&gt;height.this -&gt;height.this ->name." is 20cm.";
}
function W(){
echo this&gt;weight.this -&gt;weight.this ->name." is 2kg."
}
}
$animal = new cat();
$animal ->name = “key”;
$animal -> eat();
echo “\n”;
$animal -> H();
echo “\n”;
$animal -> W();
echo “\n”;
?>
玩转PHP(三)

相关文章: