php生成对象的研究

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生成对象的研究

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(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();
php生成对象的研究

php生成对象的研究,布布扣,bubuko.com

php生成对象的研究

上一篇:为网站减负的十大措施(转)


下一篇:私人定制,十款最佳Node.js MVC框架