PHP面向对象程序设计继承用法简单示例 本文实例讲述了PHP面向对象程序设计继承用法。分享给大家供大家参考,具体如下: name = $nameStr; echo "

$this->name : ",self::$count," : parent : __construct

"; } function work(){ echo "

$this->name is working

"; } function __destruct(){ echo "

parent unset $this->name

"; } } class Managers extends Employees{ private $pos = null; function __construct($p,$nameStr){ parent::$count++; parent::__construct($nameStr); $this->pos = $p; echo "

$this->name , $this->pos : self : __construct

"; } function assignJob(){ echo "

$this->name assign jobs

"; } function getName(){ return $this->name; } function __destruct(){ echo "

self unset $this->name

"; } } class Programmers extends Employees{ function code(){ echo "

$this->name is coding

"; } 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 "

{$e3->getName()}

"; //echo "

$e1->name

"; if($e2 instanceof Employees){ echo "

ok

"; }else{ echo "

no

"; } 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程序设计有所帮助。