3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ParentClass { private $property = 'parent private property'; } class C extends ParentClass { private $property = 'child private property'; } $object = new C(); // Using ReflectionProperty $refProperty = new ReflectionProperty(ParentClass::class, 'property'); $refProperty->setAccessible(true); $startReflection = microtime(true); $reflectionValue = $refProperty->getValue($object); $endReflection = microtime(true); // Using array casting $startArray = microtime(true); $arrayValue = (array)$object; $arrayValueDirect = $arrayValue["\0" . ParentClass::class . "\0" . 'property']; $endArray = microtime(true); echo "Reflection Value: $reflectionValue\n"; echo "Array Casting Value: $arrayValueDirect\n"; echo "Reflection Time: " . ($endReflection - $startReflection) . " seconds\n"; echo "Array Casting Time: " . ($endArray - $startArray) . " seconds\n"; // Using ReflectionProperty $refProperty = new ReflectionProperty(ParentClass::class, 'property'); $refProperty->setAccessible(true); $startReflection = microtime(true); $reflectionValue = $refProperty->getValue($object); $endReflection = microtime(true); // Using array casting $startArray = microtime(true); $arrayValue = (array)$object; $arrayValueDirect = $arrayValue["\0" . ParentClass::class . "\0" . 'property']; $endArray = microtime(true); echo "Reflection Value: $reflectionValue\n"; echo "Array Casting Value: $arrayValueDirect\n"; echo "Reflection Time: " . ($endReflection - $startReflection) . " seconds\n"; echo "Array Casting Time: " . ($endArray - $startArray) . " seconds\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JL4YU
function name:  (null)
number of ops:  100
compiled vars:  !0 = $object, !1 = $refProperty, !2 = $startReflection, !3 = $reflectionValue, !4 = $endReflection, !5 = $startArray, !6 = $arrayValue, !7 = $arrayValueDirect, !8 = $endArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   NEW                                              $9      'C'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $9
   14     3        NEW                                              $12     'ReflectionProperty'
          4        SEND_VAL_EX                                              'ParentClass'
          5        SEND_VAL_EX                                              'property'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $12
   15     8        INIT_METHOD_CALL                                         !1, 'setAccessible'
          9        SEND_VAL_EX                                              <true>
         10        DO_FCALL                                      0          
   16    11        INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $16     
         14        ASSIGN                                                   !2, $16
   17    15        INIT_METHOD_CALL                                         !1, 'getValue'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $18     
         18        ASSIGN                                                   !3, $18
   18    19        INIT_FCALL                                               'microtime'
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $20     
         22        ASSIGN                                                   !4, $20
   21    23        INIT_FCALL                                               'microtime'
         24        SEND_VAL                                                 <true>
         25        DO_ICALL                                         $22     
         26        ASSIGN                                                   !5, $22
   22    27        CAST                                          7  ~24     !0
         28        ASSIGN                                                   !6, ~24
   23    29        FETCH_DIM_R                                      ~26     !6, '%00ParentClass%00property'
         30        ASSIGN                                                   !7, ~26
   24    31        INIT_FCALL                                               'microtime'
         32        SEND_VAL                                                 <true>
         33        DO_ICALL                                         $28     
         34        ASSIGN                                                   !8, $28
   26    35        ROPE_INIT                                     3  ~31     'Reflection+Value%3A+'
         36        ROPE_ADD                                      1  ~31     ~31, !3
         37        ROPE_END                                      2  ~30     ~31, '%0A'
         38        ECHO                                                     ~30
   27    39        ROPE_INIT                                     3  ~34     'Array+Casting+Value%3A+'
         40        ROPE_ADD                                      1  ~34     ~34, !7
         41        ROPE_END                                      2  ~33     ~34, '%0A'
         42        ECHO                                                     ~33
   28    43        SUB                                              ~36     !4, !2
         44        CONCAT                                           ~37     'Reflection+Time%3A+', ~36
         45        CONCAT                                           ~38     ~37, '+seconds%0A'
         46        ECHO                                                     ~38
   29    47        SUB                                              ~39     !8, !5
         48        CONCAT                                           ~40     'Array+Casting+Time%3A+', ~39
         49        CONCAT                                           ~41     ~40, '+seconds%0A'
         50        ECHO                                                     ~41
   32    51        NEW                                              $42     'ReflectionProperty'
         52        SEND_VAL_EX                                              'ParentClass'
         53        SEND_VAL_EX                                              'property'
         54        DO_FCALL                                      0          
         55        ASSIGN                                                   !1, $42
   33    56        INIT_METHOD_CALL                                         !1, 'setAccessible'
         57        SEND_VAL_EX                                              <true>
         58        DO_FCALL                                      0          
   34    59        INIT_FCALL                                               'microtime'
         60        SEND_VAL                                                 <true>
         61        DO_ICALL                                         $46     
         62        ASSIGN                                                   !2, $46
   35    63        INIT_METHOD_CALL                                         !1, 'getValue'
         64        SEND_VAR_EX                                              !0
         65        DO_FCALL                                      0  $48     
         66        ASSIGN                                                   !3, $48
   36    67        INIT_FCALL                                               'microtime'
         68        SEND_VAL                                                 <true>
         69        DO_ICALL                                         $50     
         70        ASSIGN                                                   !4, $50
   39    71        INIT_FCALL                                               'microtime'
         72        SEND_VAL                                                 <true>
         73        DO_ICALL                                         $52     
         74        ASSIGN                                                   !5, $52
   40    75        CAST                                          7  ~54     !0
         76        ASSIGN                                                   !6, ~54
   41    77        FETCH_DIM_R                                      ~56     !6, '%00ParentClass%00property'
         78        ASSIGN                                                   !7, ~56
   42    79        INIT_FCALL                                               'microtime'
         80        SEND_VAL                                                 <true>
         81        DO_ICALL                                         $58     
         82        ASSIGN                                                   !8, $58
   44    83        ROPE_INIT                                     3  ~61     'Reflection+Value%3A+'
         84        ROPE_ADD                                      1  ~61     ~61, !3
         85        ROPE_END                                      2  ~60     ~61, '%0A'
         86        ECHO                                                     ~60
   45    87        ROPE_INIT                                     3  ~64     'Array+Casting+Value%3A+'
         88        ROPE_ADD                                      1  ~64     ~64, !7
         89        ROPE_END                                      2  ~63     ~64, '%0A'
         90        ECHO                                                     ~63
   46    91        SUB                                              ~66     !4, !2
         92        CONCAT                                           ~67     'Reflection+Time%3A+', ~66
         93        CONCAT                                           ~68     ~67, '+seconds%0A'
         94        ECHO                                                     ~68
   47    95        SUB                                              ~69     !8, !5
         96        CONCAT                                           ~70     'Array+Casting+Time%3A+', ~69
         97        CONCAT                                           ~71     ~70, '+seconds%0A'
         98        ECHO                                                     ~71
         99      > RETURN                                                   1

Class ParentClass: [no user functions]
Class C: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.37 ms | 1445 KiB | 14 Q