• 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
    ";
        }
    }
    
    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();
  • 相关阅读:
    浅谈js的继承
    Android调用jni全过程,方便以后操作
    oracle中查找执行效率低下的SQL
    EBS R12 怎么修改APPS密码
    oracle查看系统资源占用情况
    ramfs
    091104 晴
    周六
    注意调整
    短信收到
  • 原文地址:https://www.cnblogs.com/jami918/p/3606039.html
Copyright © 2020-2023  润新知