• $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.

    */

  • 相关阅读:
    dubbo服务集群
    Caused by: java.sql.SQLException: No value specified for parameter 2
    logstash 解析windows iis日志
    maven fastdfs_client.jar找不到问题解决
    logstsha 发送数据到数据节点
    redis被黑客入侵
    logstash 自定义正则
    Caused by: java.sql.SQLException: Generated keys not requested
    BeanFactory not initialized or already closed
    Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : U
  • 原文地址:https://www.cnblogs.com/rsapaper/p/5828121.html
Copyright © 2020-2023  润新知