zoukankan      html  css  js  c++  java
  • 008-对象—— 对象$this self parent 内存方式及使用方法讲解

    <?php
    /**
     *
     */
    /*class Web{
        private $webname;
        private $weburl;
        function __construct($webname,$weburl)
        {
            $this->webname=$webname;
            $this->weburl=$weburl;
        }
        function _getwebinfo(){
            return "网站名称".$this->webname."   ".$this->weburl;
        }
    }
    $hdw=new Web("蓝天","www.lantian.com");
    echo $hdw->_getwebinfo();*/
    
    //$this代表当前对象
    /*class a{
        function show(){
            $this->d();
        }
        function d(){
            echo 1111;
        }
    }
    class b extends a{
        function d(){
            echo 2222;
        }
    }
    $e=new b();
    $e->show(); //输出:2222*/
    
    
    //self:当前类的引用。
    /*class a{
        function show(){
            self::d();
        }
        function d(){
            echo 1111;
        }
    }
    
    class b extends a{
        function d(){
            echo 2222;
        }
    }
    $e=new b();
    $e->show(); //输出:1111*/
    
    //子类没有对应方法时,去找父类的方法
    /*class e{
        function m(){
            echo 111;
        }
    }
    class r extends e{
    }
    $k=new r();
    $k->m();//输出:111*/
    
    //子类有对应的方法时,不找父类的方法了
    /*class e{
        function m(){
            echo 111;
        }
    }
    class r extends e{
        function m(){
            echo 222;
        }
    }
    $k=new r();
    $k->m();//输出:222*/
    
    //重写方法的时候,找父类的方法。
    /*class e{
        function m(){
            echo 111;
        }
    }
    class r extends e{
        function m(){
            parent::m();
        }
    }
    $k=new r();
    $k->m();//输出:111*/
    
    
    class TPL{
        private $tplpath;
        private $catch;
        private $catechTime;
        function __construct()
        {
            $this->tplpath="../template/default";
            $this->catch="../catch";
            $this->catechTime=3600;
        }
        function display($tplFile){
    //        echo "载入模板文件:".$tplFile;
            echo "载入模板文件:{$tplFile}";
            echo "<br/>=========================<br/>";
        }
        function reso(){
            echo "解析模板标签";
        }
        function wrong(){
            echo "....";
        }
    }
    class APP extends TPL{
        function __construct()
        {
            parent::__construct(); //拿过来父类的方法。
            echo "<br/>app<br/>";//自己的方法
        }
    }
    class admin extends APP{
    
    }
    $chanel=new admin();
    $chanel->display("index.html");
    
    class member extends APP{
    
    }
    $user=new member();
    $user->display('member/user.html');
    

      

  • 相关阅读:
    CSS(二)样式优先级别和css的单位刻度
    Ural 1416 Confidential
    UVA 10600
    UESTC 1558 Charitable Exchange
    ZOJ 3349 Special Subsequence
    mysql主从复制
    debian安装mysql
    lpeg
    多线程程序 怎样查看每个线程的cpu占用
    linux TIME_WAIT过多的解决方法
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/7984963.html
Copyright © 2011-2022 走看看