3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ArraySerializableInterface {} class Baz { private $BazEvent = 'BazEvent'; } class Bar{ private $event = 'BarEvent'; private $secendClass; /** * Constructor. */ public function __construct() { $this->secendClass = [ new Baz(), ]; } } class Foo { private $test = 'sd'; private $firstClass; /** * Constructor. */ public function __construct() { $this->firstClass = [ new Bar(), new Bar(), new Bar(), new Bar(), ]; } public function dismount($object = null) { $object = $object?: $this; $reflectionClass = new \ReflectionClass(get_class($object)); $array =[]; foreach ($reflectionClass->getProperties() as $property) { $property->setAccessible(true); $value = $property->getValue($object); if (is_array($value)) { $this->foo($value, $property, $array); continue; } $array[$property->getName()] = $value; $property->setAccessible(false); } return $array; } private function foo($value, \ReflectionProperty $property, &$array) { foreach ($value as $name => $subValue) { if (is_object($subValue)) { $array[$property->getName()][$name] = $this->dismount($subValue); continue; } if (is_array($subValue)) { throw new \RuntimeException('Multi-array is currently not supported.'); continue; } $array[$property->getName()][$name] = $subValue; } } } $foo = new Foo; var_dump( $foo->dismount());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2LFU7
function name:  (null)
number of ops:  9
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   89     0  E >   NEW                                              $1      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   90     3        INIT_FCALL                                               'var_dump'
          4        INIT_METHOD_CALL                                         !0, 'dismount'
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Class ArraySerializableInterface: [no user functions]
Class Baz: [no user functions]
Class Bar:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2LFU7
function name:  __construct
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   NEW                                              $1      'Baz'
          1        DO_FCALL                                      0          
          2        INIT_ARRAY                                       ~3      $1
   19     3        ASSIGN_OBJ                                               'secendClass'
   20     4        OP_DATA                                                  ~3
   22     5      > RETURN                                                   null

End of function __construct

End of class Bar.

Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2LFU7
function name:  __construct
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   NEW                                              $1      'Bar'
          1        DO_FCALL                                      0          
          2        INIT_ARRAY                                       ~3      $1
   37     3        NEW                                              $4      'Bar'
          4        DO_FCALL                                      0          
          5        ADD_ARRAY_ELEMENT                                ~3      $4
   38     6        NEW                                              $6      'Bar'
          7        DO_FCALL                                      0          
          8        ADD_ARRAY_ELEMENT                                ~3      $6
   39     9        NEW                                              $8      'Bar'
         10        DO_FCALL                                      0          
         11        ADD_ARRAY_ELEMENT                                ~3      $8
   35    12        ASSIGN_OBJ                                               'firstClass'
   39    13        OP_DATA                                                  ~3
   41    14      > RETURN                                                   null

End of function __construct

Function dismount:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 38
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 38
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 30
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/2LFU7
function name:  dismount
number of ops:  41
compiled vars:  !0 = $object, !1 = $reflectionClass, !2 = $array, !3 = $property, !4 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV_INIT                                        !0      null
   45     1        JMP_SET                                          ~5      !0, ->4
          2        FETCH_THIS                                       ~6      
          3        QM_ASSIGN                                        ~5      ~6
          4        ASSIGN                                                   !0, ~5
   46     5        NEW                                              $8      'ReflectionClass'
          6        GET_CLASS                                        ~9      !0
          7        SEND_VAL_EX                                              ~9
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $8
   47    10        ASSIGN                                                   !2, <array>
   48    11        INIT_METHOD_CALL                                         !1, 'getProperties'
         12        DO_FCALL                                      0  $13     
         13      > FE_RESET_R                                       $14     $13, ->38
         14    > > FE_FETCH_R                                               $14, !3, ->38
   49    15    >   INIT_METHOD_CALL                                         !3, 'setAccessible'
         16        SEND_VAL_EX                                              <true>
         17        DO_FCALL                                      0          
   50    18        INIT_METHOD_CALL                                         !3, 'getValue'
         19        SEND_VAR_EX                                              !0
         20        DO_FCALL                                      0  $16     
         21        ASSIGN                                                   !4, $16
   52    22        TYPE_CHECK                                  128          !4
         23      > JMPZ                                                     ~18, ->30
   53    24    >   INIT_METHOD_CALL                                         'foo'
         25        SEND_VAR_EX                                              !4
         26        SEND_VAR_EX                                              !3
         27        SEND_VAR_EX                                              !2
         28        DO_FCALL                                      0          
   55    29      > JMP                                                      ->14
   58    30    >   INIT_METHOD_CALL                                         !3, 'getName'
         31        DO_FCALL                                      0  $20     
         32        ASSIGN_DIM                                               !2, $20
         33        OP_DATA                                                  !4
   59    34        INIT_METHOD_CALL                                         !3, 'setAccessible'
         35        SEND_VAL_EX                                              <false>
         36        DO_FCALL                                      0          
   48    37      > JMP                                                      ->14
         38    >   FE_FREE                                                  $14
   62    39      > RETURN                                                   !2
   63    40*     > RETURN                                                   null

End of function dismount

Function foo:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 30
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 30
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 24
Branch analysis from position: 19
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/2LFU7
function name:  foo
number of ops:  32
compiled vars:  !0 = $value, !1 = $property, !2 = $array, !3 = $subValue, !4 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   67     3      > FE_RESET_R                                       $5      !0, ->30
          4    > > FE_FETCH_R                                       ~6      $5, !3, ->30
          5    >   ASSIGN                                                   !4, ~6
   68     6        TYPE_CHECK                                  256          !3
          7      > JMPZ                                                     ~8, ->17
   69     8    >   INIT_METHOD_CALL                                         !1, 'getName'
          9        DO_FCALL                                      0  $9      
         10        INIT_METHOD_CALL                                         'dismount'
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0  $12     
         13        FETCH_DIM_W                                      $10     !2, $9
         14        ASSIGN_DIM                                               $10, !4
         15        OP_DATA                                                  $12
   71    16      > JMP                                                      ->4
   73    17    >   TYPE_CHECK                                  128          !3
         18      > JMPZ                                                     ~13, ->24
   74    19    >   NEW                                              $14     'RuntimeException'
         20        SEND_VAL_EX                                              'Multi-array+is+currently+not+supported.'
         21        DO_FCALL                                      0          
         22      > THROW                                         0          $14
   76    23*       JMP                                                      ->4
   79    24    >   INIT_METHOD_CALL                                         !1, 'getName'
         25        DO_FCALL                                      0  $16     
         26        FETCH_DIM_W                                      $17     !2, $16
         27        ASSIGN_DIM                                               $17, !4
         28        OP_DATA                                                  !3
   67    29      > JMP                                                      ->4
         30    >   FE_FREE                                                  $5
   83    31      > RETURN                                                   null

End of function foo

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.12 ms | 1404 KiB | 15 Q