<?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 "; } } 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 "; } } 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 "; } } $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();