php 面向对象 示例,php中面向对象示例
生活随笔
收集整理的這篇文章主要介紹了
php 面向对象 示例,php中面向对象示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Gun.class.php文件
?php
class Gun{
//定義累的屬性
public $type;
public $color;
public $bulletnum;
public $weight;
//定義類的方法
function kill(){
return"士兵".$this->type."的手槍,重量".$this->weight.",殺死了敵人!";
}
function sound(){
return "發出慘叫的聲音";
}
}
?>
gun.php文件
include 'Gun.class.php';
//槍的類型
$shouqiang = new gun();
$shouqiang->type="小型";
$shouqiang->color="紅色";
$shouqiang->bulletnum="20發";
$shouqiang->weight="50克";
echo $shouqiang->kill();
echo $shouqiang->sound();
?>
總結
以上是生活随笔為你收集整理的php 面向对象 示例,php中面向对象示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一般军校毕业的军医有多少人
- 下一篇: php 调用redfish,Redfis