• 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');
    

      

  • 相关阅读:
    JWT在ASP.NET Core3.1的应用
    .NET Core 3.0中IAsyncEnumerable<T>有什么大不了的?
    C#类继承中构造函数的执行序列
    C#中的out 参数,ref参数,值参数
    ABP之启动配置
    ABP之模块系统
    ABP之N层架构
    ABP之什么是ABP(ASP.NET Boilerplate)
    如何使用ASP.NET Core、EF Core、ABP(ASP.NET Boilerplate)创建分层的Web应用程序(第一部分)
    ABP之Setting
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/7984963.html
Copyright © 2020-2023  润新知