3v4l.org

run code in 300+ PHP versions simultaneously
<?php // 费了我好大功夫, 把这些都总结到一个例子里面了 // PHP5.0 - PHP5.5 测试通过 class A { //类常量 const constValue = "constValue\n"; //类属性 public $property = "properties\n"; //静态属性 static public $staticProperty = "staticProperty\n"; //普通函数 public function func() { } //静态函数 static public function staticFunc() { } } $xxoo = new A; //访问实例的属性 print $xxoo->property; //访问实例的函数 print $xxoo->func(); //也可以借助实例来访问静态成员 //访问函数要用箭头,属性要用双冒号 print $xxoo->staticFunc(); print $xxoo::$staticProperty; //如果不借助实例,那就直接用类名加双冒号 print A::staticFunc(); print A::constValue; //静态属性要加美元符号 print A::$staticProperty; //继承类A class B extends A { //覆盖父类的属性 public $property = "covered-properties\n"; //覆盖父类的静态属性 static public $staitcProperty = "covered-staitcProperties\n"; //覆盖父类的函数 public function func() { //访问自己的属性 print $this->property; //访问从父类继承来的静态属性 print self::$staticProperty; //访问自己的(静态)函数 print $this->staticFunc(); //强制指定访问父类(而不是自己)的函数 print parent::func(); } //覆盖父类的静态函数 static public function staticFunc() { //因为没有$this, 所以用self访问自己的静态属性 print self::$staitcProperty; } } //运行一下上面的例子 $xxoo = new B; $xxoo->func(); B::staticFunc();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YgvCh
function name:  (null)
number of ops:  28
compiled vars:  !0 = $xxoo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   NEW                                              $1      'A'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   32     3        FETCH_OBJ_R                                      ~4      !0, 'property'
          4        ECHO                                                     ~4
   34     5        INIT_METHOD_CALL                                         !0, 'func'
          6        DO_FCALL                                      0  $5      
          7        ECHO                                                     $5
   38     8        INIT_METHOD_CALL                                         !0, 'staticFunc'
          9        DO_FCALL                                      0  $6      
         10        ECHO                                                     $6
   39    11        FETCH_CLASS                                   0  $7      !0
         12        FETCH_STATIC_PROP_R          unknown             ~8      'staticProperty'
         13        ECHO                                                     ~8
   42    14        INIT_STATIC_METHOD_CALL                                  'A', 'staticFunc'
         15        DO_FCALL                                      0  $9      
         16        ECHO                                                     $9
   43    17        ECHO                                                     'constValue%0A'
   45    18        FETCH_STATIC_PROP_R          unknown             ~10     'staticProperty'
         19        ECHO                                                     ~10
   81    20        NEW                                              $11     'B'
         21        DO_FCALL                                      0          
         22        ASSIGN                                                   !0, $11
   82    23        INIT_METHOD_CALL                                         !0, 'func'
         24        DO_FCALL                                      0          
   83    25        INIT_STATIC_METHOD_CALL                                  'B', 'staticFunc'
         26        DO_FCALL                                      0          
         27      > RETURN                                                   1

Class A:
Function func:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YgvCh
function name:  func
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E > > RETURN                                                   null

End of function func

Function staticfunc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YgvCh
function name:  staticFunc
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E > > RETURN                                                   null

End of function staticfunc

End of class A.

Class B:
Function func:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YgvCh
function name:  func
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   FETCH_OBJ_R                                      ~0      'property'
          1        ECHO                                                     ~0
   64     2        FETCH_STATIC_PROP_R          unknown             ~1      'staticProperty'
          3        ECHO                                                     ~1
   67     4        INIT_METHOD_CALL                                         'staticFunc'
          5        DO_FCALL                                      0  $2      
          6        ECHO                                                     $2
   69     7        INIT_STATIC_METHOD_CALL                                  'func'
          8        DO_FCALL                                      0  $3      
          9        ECHO                                                     $3
   70    10      > RETURN                                                   null

End of function func

Function staticfunc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YgvCh
function name:  staticFunc
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'staitcProperty'
          1        ECHO                                                     ~0
   77     2      > RETURN                                                   null

End of function staticfunc

End of class B.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.79 ms | 1399 KiB | 13 Q