3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 'blah1' => 1, 'blah2' => 2, 'blah3' => 3 ); class Blah { public static $blah1 = 4; protected static $blah2 = 5; private static $blah3 = 6; } $rc = new ReflectionClass('Blah'); // brand new ReflectionClass var_dump($rc); $static = $rc->getProperties(ReflectionProperty::IS_STATIC); $obj = $rc->newInstanceWithoutConstructor(); foreach($static as $prop){ if(!empty($arr[$prop->getName()])){ $prop->setAccessible(true); $prop->setValue($obj, $arr[$prop->getName()]); //$rc->setStaticPropertyValue($prop->getName(), $arr[$prop->getName()]); } } $obj2 = $rc->newInstanceWithoutConstructor(); // instantiate class after ReflectionClass has set all property values var_dump($obj2); var_dump($obj2::$blah1); // class instantiated before ReflectionClass captured ReflectionClass values // but after we have called "setValue" var_dump($obj); var_dump($obj::$blah1);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 34
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 34
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 33
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 33
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/SUXK5
function name:  (null)
number of ops:  55
compiled vars:  !0 = $arr, !1 = $rc, !2 = $static, !3 = $obj, !4 = $prop, !5 = $obj2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   16     1        NEW                                              $7      'ReflectionClass'
          2        SEND_VAL_EX                                              'Blah'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $7
   19     5        INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
   21     8        INIT_METHOD_CALL                                         !1, 'getProperties'
          9        SEND_VAL_EX                                              16
         10        DO_FCALL                                      0  $11     
         11        ASSIGN                                                   !2, $11
   22    12        INIT_METHOD_CALL                                         !1, 'newInstanceWithoutConstructor'
         13        DO_FCALL                                      0  $13     
         14        ASSIGN                                                   !3, $13
   23    15      > FE_RESET_R                                       $15     !2, ->34
         16    > > FE_FETCH_R                                               $15, !4, ->34
   24    17    >   INIT_METHOD_CALL                                         !4, 'getName'
         18        DO_FCALL                                      0  $16     
         19        ISSET_ISEMPTY_DIM_OBJ                         1  ~17     !0, $16
         20        BOOL_NOT                                         ~18     ~17
         21      > JMPZ                                                     ~18, ->33
   25    22    >   INIT_METHOD_CALL                                         !4, 'setAccessible'
         23        SEND_VAL_EX                                              <true>
         24        DO_FCALL                                      0          
   26    25        INIT_METHOD_CALL                                         !4, 'setValue'
         26        SEND_VAR_EX                                              !3
         27        CHECK_FUNC_ARG                                           
         28        INIT_METHOD_CALL                                         !4, 'getName'
         29        DO_FCALL                                      0  $20     
         30        FETCH_DIM_FUNC_ARG                               $21     !0, $20
         31        SEND_FUNC_ARG                                            $21
         32        DO_FCALL                                      0          
   23    33    > > JMP                                                      ->16
         34    >   FE_FREE                                                  $15
   30    35        INIT_METHOD_CALL                                         !1, 'newInstanceWithoutConstructor'
         36        DO_FCALL                                      0  $23     
         37        ASSIGN                                                   !5, $23
   33    38        INIT_FCALL                                               'var_dump'
         39        SEND_VAR                                                 !5
         40        DO_ICALL                                                 
   34    41        INIT_FCALL                                               'var_dump'
         42        FETCH_CLASS                                   0  $26     !5
         43        FETCH_STATIC_PROP_R          unknown             ~27     'blah1'
         44        SEND_VAL                                                 ~27
         45        DO_ICALL                                                 
   38    46        INIT_FCALL                                               'var_dump'
         47        SEND_VAR                                                 !3
         48        DO_ICALL                                                 
   39    49        INIT_FCALL                                               'var_dump'
         50        FETCH_CLASS                                   0  $30     !3
         51        FETCH_STATIC_PROP_R          unknown             ~31     'blah1'
         52        SEND_VAL                                                 ~31
         53        DO_ICALL                                                 
         54      > RETURN                                                   1

Class Blah: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.95 ms | 1400 KiB | 15 Q