3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ArraySerializableInterface {} class Baz { private $eventq = 'test222'; } class Bar{ private $event = 'test'; private $test3; /** * Constructor. */ public function __construct() { $this->test3 = [ new Baz(), ]; } } class Foo { private $test = 'sd'; private $test2; /** * Constructor. */ public function __construct() { $this->test2 = [ new Bar(), new Bar(), new Bar(), new Bar(), [ new Baz(), new Baz(), ] ]; } 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)) { $this->foo($subValue, $property, $array); 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/fYsPs
function name:  (null)
number of ops:  9
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   92     0  E >   NEW                                              $1      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   93     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/fYsPs
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                                               'test3'
   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/fYsPs
function name:  __construct
number of ops:  22
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
   41    12        NEW                                              $10     'Baz'
         13        DO_FCALL                                      0          
         14        INIT_ARRAY                                       ~12     $10
   42    15        NEW                                              $13     'Baz'
         16        DO_FCALL                                      0          
         17        ADD_ARRAY_ELEMENT                                ~12     $13
         18        ADD_ARRAY_ELEMENT                                ~3      ~12
   35    19        ASSIGN_OBJ                                               'test2'
   42    20        OP_DATA                                                  ~3
   45    21      > 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/fYsPs
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
-------------------------------------------------------------------------------------
   47     0  E >   RECV_INIT                                        !0      null
   49     1        JMP_SET                                          ~5      !0, ->4
          2        FETCH_THIS                                       ~6      
          3        QM_ASSIGN                                        ~5      ~6
          4        ASSIGN                                                   !0, ~5
   50     5        NEW                                              $8      'ReflectionClass'
          6        GET_CLASS                                        ~9      !0
          7        SEND_VAL_EX                                              ~9
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $8
   51    10        ASSIGN                                                   !2, <array>
   52    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
   53    15    >   INIT_METHOD_CALL                                         !3, 'setAccessible'
         16        SEND_VAL_EX                                              <true>
         17        DO_FCALL                                      0          
   54    18        INIT_METHOD_CALL                                         !3, 'getValue'
         19        SEND_VAR_EX                                              !0
         20        DO_FCALL                                      0  $16     
         21        ASSIGN                                                   !4, $16
   56    22        TYPE_CHECK                                  128          !4
         23      > JMPZ                                                     ~18, ->30
   57    24    >   INIT_METHOD_CALL                                         'foo'
         25        SEND_VAR_EX                                              !4
         26        SEND_VAR_EX                                              !3
         27        SEND_VAR_EX                                              !2
         28        DO_FCALL                                      0          
   59    29      > JMP                                                      ->14
   62    30    >   INIT_METHOD_CALL                                         !3, 'getName'
         31        DO_FCALL                                      0  $20     
         32        ASSIGN_DIM                                               !2, $20
         33        OP_DATA                                                  !4
   63    34        INIT_METHOD_CALL                                         !3, 'setAccessible'
         35        SEND_VAL_EX                                              <false>
         36        DO_FCALL                                      0          
   52    37      > JMP                                                      ->14
         38    >   FE_FREE                                                  $14
   66    39      > RETURN                                                   !2
   67    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 = 31
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 31
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 = 25
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/fYsPs
function name:  foo
number of ops:  33
compiled vars:  !0 = $value, !1 = $property, !2 = $array, !3 = $subValue, !4 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   71     3      > FE_RESET_R                                       $5      !0, ->31
          4    > > FE_FETCH_R                                       ~6      $5, !3, ->31
          5    >   ASSIGN                                                   !4, ~6
   72     6        TYPE_CHECK                                  256          !3
          7      > JMPZ                                                     ~8, ->17
   73     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
   75    16      > JMP                                                      ->4
   77    17    >   TYPE_CHECK                                  128          !3
         18      > JMPZ                                                     ~13, ->25
   78    19    >   INIT_METHOD_CALL                                         'foo'
         20        SEND_VAR                                                 !3
         21        SEND_VAR                                                 !1
         22        SEND_REF                                                 !2
         23        DO_FCALL                                      0          
   80    24      > JMP                                                      ->4
   83    25    >   INIT_METHOD_CALL                                         !1, 'getName'
         26        DO_FCALL                                      0  $15     
         27        FETCH_DIM_W                                      $16     !2, $15
         28        ASSIGN_DIM                                               $16, !4
         29        OP_DATA                                                  !3
   71    30      > JMP                                                      ->4
         31    >   FE_FREE                                                  $5
   86    32      > RETURN                                                   null

End of function foo

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
186.89 ms | 1400 KiB | 15 Q