php生成对象的研究
<?php abstract class E{ protected $name; function __construct($name){ $this->name = $name; } abstract function fire(); } class M extends E{ function fire(){ print "{$this->name}:iiiii\n"; } } class N{ private $e = array(); function adde($ename){ $this->e[] = new M($ename); } function p(){ if(count($this->e)>0){ $emp = array_pop($this->e);//这里要注意array_pos这个函数 $emp->fire(); } } } $boss = new N(); $boss->adde(‘harry‘); var_dump($boss); $boss->adde(‘bob‘); var_dump($boss); $boss->p();
<?php abstract class E{ protected $name; function __construct($name){ $this->name = $name; } abstract function fire(); } class M extends E{ function fire(){ print "{$this->name}:iiiii\n"; } } class N{ private $e = array(); function adde(E $ename){ $this->e[] = $ename; } function p(){ if(count($this->e)>0){ $emp = array_pop($this->e); //var_dump($emp); $emp->fire(); } } } class C extends E{ function fire(){ print "{$this->name}:oooooo\n"; } } $boss = new N(); $boss->adde(new M(‘harry‘)); var_dump($boss); $boss->adde(new C(‘bob‘)); var_dump($boss); $boss->adde(new M(‘mary‘)); var_dump($boss); $boss->p(); var_dump($boss); $boss->p(); var_dump($boss); $boss->p();
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。