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 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 parent::$property; //强制指定访问父类(而不是自己)的函数 print parent::func(); } //覆盖父类的静态函数 static public function staticFunc() { //因为没有$this, 所以用self访问自己的静态属性 print self::$staitcProperty; //强制访问父类的静态属性 print parent::$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/YMGdu
function name:  (null)
number of ops:  25
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
   37     8        INIT_METHOD_CALL                                         !0, 'staticFunc'
          9        DO_FCALL                                      0  $6      
         10        ECHO                                                     $6
   40    11        INIT_STATIC_METHOD_CALL                                  'A', 'staticFunc'
         12        DO_FCALL                                      0  $7      
         13        ECHO                                                     $7
   41    14        ECHO                                                     'constValue%0A'
   43    15        FETCH_STATIC_PROP_R          unknown             ~8      'staticProperty'
         16        ECHO                                                     ~8
   81    17        NEW                                              $9      'B'
         18        DO_FCALL                                      0          
         19        ASSIGN                                                   !0, $9
   82    20        INIT_METHOD_CALL                                         !0, 'func'
         21        DO_FCALL                                      0          
   83    22        INIT_STATIC_METHOD_CALL                                  'B', 'staticFunc'
         23        DO_FCALL                                      0          
         24      > RETURN                                                   1

Class A:
Function func:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YMGdu
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/YMGdu
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/YMGdu
function name:  func
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   FETCH_OBJ_R                                      ~0      'property'
          1        ECHO                                                     ~0
   62     2        FETCH_CLASS_CONSTANT                             ~1      'staticProperty'
          3        ECHO                                                     ~1
   65     4        FETCH_STATIC_PROP_R          unknown             ~2      'property'
          5        ECHO                                                     ~2
   67     6        INIT_STATIC_METHOD_CALL                                  'func'
          7        DO_FCALL                                      0  $3      
          8        ECHO                                                     $3
   68     9      > 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/YMGdu
function name:  staticFunc
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'staitcProperty'
          1        ECHO                                                     ~0
   76     2        FETCH_STATIC_PROP_R          unknown             ~1      'staitcProperty'
          3        ECHO                                                     ~1
   77     4      > RETURN                                                   null

End of function staticfunc

End of class B.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.72 ms | 1399 KiB | 13 Q