zoukankan      html  css  js  c++  java
  • $this

    php.net

     1 <?php
     2 
     3 
     4 class A 
     5 {
     6     function foo()
     7     {
     8         if (isset($this)) {
     9             echo '$this is defined (',get_class($this),')'."\n";
    10         } else {
    11             echo '$this is not defined.'."\n";
    12         }    
    13     }
    14 }
    15 
    16 class B 
    17 {
    18     function bar()
    19     {
    20         A::foo();
    21     }
    22 }
    23 
    24 $a = new A();
    25 $a->foo();
    26 
    27 A::foo();
    28 $b = new B();
    29 $b->bar();
    30 
    31 B::bar();

    $this is defined (A) 

    ( ! ) Strict standards: Non-static method A::foo() should not be called statically in D:\wamp64\www\w0827pm\w.php on line 27
    Call Stack
    #TimeMemoryFunctionLocation
    1 0.0020 241448 {main}( ) ...\w.php:0

    $this is not defined. 

    ( ! ) Deprecated: Non-static method A::foo() should not be called statically, assuming $this from incompatible context in D:\wamp64\www\w0827pm\w.php on line 20
    Call Stack
    #TimeMemoryFunctionLocation
    1 0.0020 241448 {main}( ) ...\w.php:0
    2 0.0030 242352 B->bar( ) ...\w.php:29

    $this is defined (B) 

    ( ! ) Strict standards: Non-static method B::bar() should not be called statically in D:\wamp64\www\w0827pm\w.php on line 31
    Call Stack
    #TimeMemoryFunctionLocation
    1 0.0020 241448 {main}( ) ...\w.php:0


    ( ! ) Strict standards: Non-static method A::foo() should not be called statically in D:\wamp64\www\w0827pm\w.php on line 20
    Call Stack
    #TimeMemoryFunctionLocation
    1 0.0020 241448 {main}( ) ...\w.php:0
    2 0.0030 242352 B::bar( ) ...\w.php:31

    $this is not defined.

    /*

    The pseudo-variable $this is available when a    method is called from within an object    context. $this is a reference to the calling    object (usually the object to which the method belongs, but    possibly another object, if the method is called     statically from the context    of a secondary object).

      As of PHP 7.0.0 calling a non-static method statically from an incompatible  context results in $this being undefined inside the method. Calling a    non-static method statically from an incompatible context has been  deprecated as of PHP 5.6.0. As of PHP 7.0.0 calling a non-static method    statically has been generally deprecated (even if called from a compatible  context). Before PHP 5.6.0 such calls already triggered a strict notice.

    */

  • 相关阅读:
    数据分页和使用存储过程的数据分页
    【转】让你10分钟搞定Mac--最简单快速的虚拟安装
    使开发更便捷——Visual Studio 使用技巧——快捷键
    【基础知识】.Net基础加强 第二天
    【基础知识】.Net基础加强第01天
    【基础知识】Asp.Net基础三
    C# 文件操作 之 删除、复制、转移多个文件[转]
    C#中拷贝指定文件夹下的所有文件夹目录到指定文件夹中的方法
    巧用DateTime会使你处理这些事来变轻松多了
    Style.BasedOn 属性
  • 原文地址:https://www.cnblogs.com/rsapaper/p/5828121.html
Copyright © 2011-2022 走看看