3v4l.org

run code in 300+ PHP versions simultaneously
<?php class GrandPa { protected $elements = array( 'a' => 1, 'b' => 2, ); public function mergeElements($childElements = null) { // 用反射实现 $elements = $this->elements; $class = new ReflectionClass($this); while($class = $class->getParentClass()) { $properties = $class->getDefaultProperties(); if(isset($properties['elements'])) { $elements = array_merge($properties['elements'], $elements); } } return $elements; } } class Father extends GrandPa { protected $elements = array( 'c' => 3, ); } class Me extends Father{ protected $elements = array( 'd' => 4, ); } $stime=microtime(true); for ($i=1;$i<=100000;$i++){ $me = new Me(); $me->mergeElements(); } $etime=microtime(true); echo $etime-$stime;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
Branch analysis from position: 6
filename:       /in/tiGIN
function name:  (null)
number of ops:  21
compiled vars:  !0 = $stime, !1 = $i, !2 = $me, !3 = $etime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                               'microtime'
          1        SEND_VAL                                                 <true>
          2        DO_ICALL                                         $4      
          3        ASSIGN                                                   !0, $4
   38     4        ASSIGN                                                   !1, 1
          5      > JMP                                                      ->12
   39     6    >   NEW                                              $7      'Me'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !2, $7
   40     9        INIT_METHOD_CALL                                         !2, 'mergeElements'
         10        DO_FCALL                                      0          
   38    11        PRE_INC                                                  !1
         12    >   IS_SMALLER_OR_EQUAL                                      !1, 100000
         13      > JMPNZ                                                    ~12, ->6
   42    14    >   INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                         $13     
         17        ASSIGN                                                   !3, $13
   43    18        SUB                                              ~15     !3, !0
         19        ECHO                                                     ~15
         20      > RETURN                                                   1

Class GrandPa:
Function mergeelements:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 9
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 9
Branch analysis from position: 24
Branch analysis from position: 9
Branch analysis from position: 20
filename:       /in/tiGIN
function name:  mergeElements
number of ops:  26
compiled vars:  !0 = $childElements, !1 = $elements, !2 = $class, !3 = $properties
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV_INIT                                        !0      null
   13     1        FETCH_OBJ_R                                      ~4      'elements'
          2        ASSIGN                                                   !1, ~4
   14     3        NEW                                              $6      'ReflectionClass'
          4        FETCH_THIS                                       $7      
          5        SEND_VAR_EX                                              $7
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !2, $6
   15     8      > JMP                                                      ->20
   16     9    >   INIT_METHOD_CALL                                         !2, 'getDefaultProperties'
         10        DO_FCALL                                      0  $10     
         11        ASSIGN                                                   !3, $10
   17    12        ISSET_ISEMPTY_DIM_OBJ                         0          !3, 'elements'
         13      > JMPZ                                                     ~12, ->20
   18    14    >   INIT_FCALL                                               'array_merge'
         15        FETCH_DIM_R                                      ~13     !3, 'elements'
         16        SEND_VAL                                                 ~13
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $14     
         19        ASSIGN                                                   !1, $14
   15    20    >   INIT_METHOD_CALL                                         !2, 'getParentClass'
         21        DO_FCALL                                      0  $16     
         22        ASSIGN                                           ~17     !2, $16
         23      > JMPNZ                                                    ~17, ->9
   21    24    > > RETURN                                                   !1
   22    25*     > RETURN                                                   null

End of function mergeelements

End of class GrandPa.

Class Father:
Function mergeelements:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 9
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 9
Branch analysis from position: 24
Branch analysis from position: 9
Branch analysis from position: 20
filename:       /in/tiGIN
function name:  mergeElements
number of ops:  26
compiled vars:  !0 = $childElements, !1 = $elements, !2 = $class, !3 = $properties
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV_INIT                                        !0      null
   13     1        FETCH_OBJ_R                                      ~4      'elements'
          2        ASSIGN                                                   !1, ~4
   14     3        NEW                                              $6      'ReflectionClass'
          4        FETCH_THIS                                       $7      
          5        SEND_VAR_EX                                              $7
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !2, $6
   15     8      > JMP                                                      ->20
   16     9    >   INIT_METHOD_CALL                                         !2, 'getDefaultProperties'
         10        DO_FCALL                                      0  $10     
         11        ASSIGN                                                   !3, $10
   17    12        ISSET_ISEMPTY_DIM_OBJ                         0          !3, 'elements'
         13      > JMPZ                                                     ~12, ->20
   18    14    >   INIT_FCALL                                               'array_merge'
         15        FETCH_DIM_R                                      ~13     !3, 'elements'
         16        SEND_VAL                                                 ~13
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $14     
         19        ASSIGN                                                   !1, $14
   15    20    >   INIT_METHOD_CALL                                         !2, 'getParentClass'
         21        DO_FCALL                                      0  $16     
         22        ASSIGN                                           ~17     !2, $16
         23      > JMPNZ                                                    ~17, ->9
   21    24    > > RETURN                                                   !1
   22    25*     > RETURN                                                   null

End of function mergeelements

End of class Father.

Class Me:
Function mergeelements:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 9
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 9
Branch analysis from position: 24
Branch analysis from position: 9
Branch analysis from position: 20
filename:       /in/tiGIN
function name:  mergeElements
number of ops:  26
compiled vars:  !0 = $childElements, !1 = $elements, !2 = $class, !3 = $properties
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV_INIT                                        !0      null
   13     1        FETCH_OBJ_R                                      ~4      'elements'
          2        ASSIGN                                                   !1, ~4
   14     3        NEW                                              $6      'ReflectionClass'
          4        FETCH_THIS                                       $7      
          5        SEND_VAR_EX                                              $7
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !2, $6
   15     8      > JMP                                                      ->20
   16     9    >   INIT_METHOD_CALL                                         !2, 'getDefaultProperties'
         10        DO_FCALL                                      0  $10     
         11        ASSIGN                                                   !3, $10
   17    12        ISSET_ISEMPTY_DIM_OBJ                         0          !3, 'elements'
         13      > JMPZ                                                     ~12, ->20
   18    14    >   INIT_FCALL                                               'array_merge'
         15        FETCH_DIM_R                                      ~13     !3, 'elements'
         16        SEND_VAL                                                 ~13
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $14     
         19        ASSIGN                                                   !1, $14
   15    20    >   INIT_METHOD_CALL                                         !2, 'getParentClass'
         21        DO_FCALL                                      0  $16     
         22        ASSIGN                                           ~17     !2, $16
         23      > JMPNZ                                                    ~17, ->9
   21    24    > > RETURN                                                   !1
   22    25*     > RETURN                                                   null

End of function mergeelements

End of class Me.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.7 ms | 1409 KiB | 17 Q