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.

    */

  • 相关阅读:
    获取文件mime类型
    PHP的CURL
    PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案
    MySQL中的group_concat函数
    MYSQL批量修改表前缀与表名sql语句
    ubuntu18.04 无法连接有线
    ffmpeg接收udp输入的h264文件流,推流到rtmp服务器
    nginx-rtmp
    tf.image.crop_and_resize
    tf.reduce_sum
  • 原文地址:https://www.cnblogs.com/rsapaper/p/5828121.html
Copyright © 2011-2022 走看看