3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ParentClass { protected readonly int $value; } trait Foo { protected readonly int $value; } class ChildClassWithoutTrait extends ParentClass { protected readonly int $value; } $reflector = new ReflectionClass(ChildClassWithoutTrait::class); $instance = $reflector->newInstanceWithoutConstructor(); var_dump( $reflector->hasProperty('value'), $prop = $reflector->getProperty('value') ); $prop->setValue($instance, 20); var_dump($instance); echo '--------------------------------------------------------------------------------------------------------', PHP_EOL; class ClassWithTraitAndNoParent { use Foo; } $reflector = new ReflectionClass(ClassWithTraitAndNoParent::class); $instance = $reflector->newInstanceWithoutConstructor(); var_dump( $reflector->hasProperty('value'), $prop = $reflector->getProperty('value') ); $prop->setValue($instance, 20); var_dump($instance); echo '--------------------------------------------------------------------------------------------------------', PHP_EOL; class ChildClassWithTrait extends ParentClass { use Foo; } $reflector = new ReflectionClass(ChildClassWithTrait::class); $instance = $reflector->newInstanceWithoutConstructor(); var_dump( $reflector->hasProperty('value'), $prop = $reflector->getProperty('value') ); $prop->setValue($instance, 20); var_dump($instance);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zbnqa
function name:  (null)
number of ops:  82
compiled vars:  !0 = $reflector, !1 = $instance, !2 = $prop
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $3      'ReflectionClass'
          1        SEND_VAL_EX                                              'ChildClassWithoutTrait'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   19     4        INIT_METHOD_CALL                                         !0, 'newInstanceWithoutConstructor'
          5        DO_FCALL                                      0  $6      
          6        ASSIGN                                                   !1, $6
   21     7        INIT_FCALL                                               'var_dump'
   22     8        INIT_METHOD_CALL                                         !0, 'hasProperty'
          9        SEND_VAL_EX                                              'value'
         10        DO_FCALL                                      0  $8      
         11        SEND_VAR                                                 $8
   23    12        INIT_METHOD_CALL                                         !0, 'getProperty'
         13        SEND_VAL_EX                                              'value'
         14        DO_FCALL                                      0  $9      
         15        ASSIGN                                           ~10     !2, $9
         16        SEND_VAL                                                 ~10
   21    17        DO_ICALL                                                 
   26    18        INIT_METHOD_CALL                                         !2, 'setValue'
         19        SEND_VAR_EX                                              !1
         20        SEND_VAL_EX                                              20
         21        DO_FCALL                                      0          
   28    22        INIT_FCALL                                               'var_dump'
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                                 
   30    25        ECHO                                                     '--------------------------------------------------------------------------------------------------------'
         26        ECHO                                                     '%0A'
   32    27        DECLARE_CLASS                                            'classwithtraitandnoparent'
   37    28        NEW                                              $14     'ReflectionClass'
         29        SEND_VAL_EX                                              'ClassWithTraitAndNoParent'
         30        DO_FCALL                                      0          
         31        ASSIGN                                                   !0, $14
   38    32        INIT_METHOD_CALL                                         !0, 'newInstanceWithoutConstructor'
         33        DO_FCALL                                      0  $17     
         34        ASSIGN                                                   !1, $17
   40    35        INIT_FCALL                                               'var_dump'
   41    36        INIT_METHOD_CALL                                         !0, 'hasProperty'
         37        SEND_VAL_EX                                              'value'
         38        DO_FCALL                                      0  $19     
         39        SEND_VAR                                                 $19
   42    40        INIT_METHOD_CALL                                         !0, 'getProperty'
         41        SEND_VAL_EX                                              'value'
         42        DO_FCALL                                      0  $20     
         43        ASSIGN                                           ~21     !2, $20
         44        SEND_VAL                                                 ~21
   40    45        DO_ICALL                                                 
   45    46        INIT_METHOD_CALL                                         !2, 'setValue'
         47        SEND_VAR_EX                                              !1
         48        SEND_VAL_EX                                              20
         49        DO_FCALL                                      0          
   47    50        INIT_FCALL                                               'var_dump'
         51        SEND_VAR                                                 !1
         52        DO_ICALL                                                 
   49    53        ECHO                                                     '--------------------------------------------------------------------------------------------------------'
         54        ECHO                                                     '%0A'
   51    55        DECLARE_CLASS                                            'childclasswithtrait', 'parentclass'
   56    56        NEW                                              $25     'ReflectionClass'
         57        SEND_VAL_EX                                              'ChildClassWithTrait'
         58        DO_FCALL                                      0          
         59        ASSIGN                                                   !0, $25
   57    60        INIT_METHOD_CALL                                         !0, 'newInstanceWithoutConstructor'
         61        DO_FCALL                                      0  $28     
         62        ASSIGN                                                   !1, $28
   59    63        INIT_FCALL                                               'var_dump'
   60    64        INIT_METHOD_CALL                                         !0, 'hasProperty'
         65        SEND_VAL_EX                                              'value'
         66        DO_FCALL                                      0  $30     
         67        SEND_VAR                                                 $30
   61    68        INIT_METHOD_CALL                                         !0, 'getProperty'
         69        SEND_VAL_EX                                              'value'
         70        DO_FCALL                                      0  $31     
         71        ASSIGN                                           ~32     !2, $31
         72        SEND_VAL                                                 ~32
   59    73        DO_ICALL                                                 
   64    74        INIT_METHOD_CALL                                         !2, 'setValue'
         75        SEND_VAR_EX                                              !1
         76        SEND_VAL_EX                                              20
         77        DO_FCALL                                      0          
   66    78        INIT_FCALL                                               'var_dump'
         79        SEND_VAR                                                 !1
         80        DO_ICALL                                                 
         81      > RETURN                                                   1

Class ParentClass: [no user functions]
Class Foo: [no user functions]
Class ChildClassWithoutTrait: [no user functions]
Class ClassWithTraitAndNoParent: [no user functions]
Class ChildClassWithTrait: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
136.72 ms | 1002 KiB | 14 Q