无为清净楼资源网 Design By www.qnjia.com
本文实例讲述了PHP面向对象程序设计继承用法。分享给大家供大家参考,具体如下:
<"<p>$this->name : ",self::$count," : parent : __construct</p>"; } function work(){ echo "<p>$this->name is working</p>"; } function __destruct(){ echo "<p>parent unset $this->name</p>"; } } class Managers extends Employees{ private $pos = null; function __construct($p,$nameStr){ parent::$count++; parent::__construct($nameStr); $this->pos = $p; echo "<p>$this->name , $this->pos : self : __construct</p>"; } function assignJob(){ echo "<p>$this->name assign jobs</p>"; } function getName(){ return $this->name; } function __destruct(){ echo "<p>self unset $this->name</p>"; } } class Programmers extends Employees{ function code(){ echo "<p>$this->name is coding</p>"; } function getName(){ return $this->name; } } $e1 = new Employees('e1'); $e2 = new MAnagers(2,'e2'); $e3 = new Programmers('e3'); $e1->work(); $e2->work(); $e3->work(); $e2->assignJob(); $e3->Code(); echo "<p>{$e3->getName()}</p>"; //echo "<p>$e1->name</p>"; if($e2 instanceof Employees){ echo "<p>ok</p>"; }else{ echo "<p>no</p>"; } unset($e1,$e2,$e3);
运行结果:
e1 : 0 : parent : __construct
e2 : 1 : parent : __construct
e2 , 2 : self : __construct
e3 : 1 : parent : __construct
e1 is working
e2 is working
e3 is working
e2 assign jobs
e3 is coding
e3
ok
parent unset e1
self unset e2
parent unset e3
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php面向对象程序设计入门教程》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
标签:
PHP,面向对象,继承
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】