3v4l.org

run code in 300+ PHP versions simultaneously
<?php /*** сложный объект ***/ $obj = new stdClass; $obj->foo = new stdClass; $obj->foo->baz = 'baz'; $obj->bar = 'bar'; /** * * Преобразование объекта в массив * * @param object $object преобразуемый объект * @reeturn array * */ function objectToArray( $object ) { if( !is_object( $object ) && !is_array( $object ) ) { return $object; } if( is_object( $object ) ) { $object = get_object_vars( $object ); } return array_map( 'objectToArray', $object ); } /*** преобразование объекта в массив ***/ $array = objectToArray( $obj ); /*** просмотр массива ***/ print_r( $array );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4vjM9
function name:  (null)
number of ops:  20
compiled vars:  !0 = $obj, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   NEW                                              $2      'stdClass'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
    4     3        NEW                                              $6      'stdClass'
          4        DO_FCALL                                      0          
          5        ASSIGN_OBJ                                               !0, 'foo'
          6        OP_DATA                                                  $6
    5     7        FETCH_OBJ_W                                      $8      !0, 'foo'
          8        ASSIGN_OBJ                                               $8, 'baz'
          9        OP_DATA                                                  'baz'
    6    10        ASSIGN_OBJ                                               !0, 'bar'
         11        OP_DATA                                                  'bar'
   30    12        INIT_FCALL                                               'objecttoarray'
         13        SEND_VAR                                                 !0
         14        DO_FCALL                                      0  $11     
         15        ASSIGN                                                   !1, $11
   33    16        INIT_FCALL                                               'print_r'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
         19      > RETURN                                                   1

Function objecttoarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 7
filename:       /in/4vjM9
function name:  objectToArray
number of ops:  21
compiled vars:  !0 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        TYPE_CHECK                                  256  ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ_EX                                          ~2      ~2, ->7
          4    >   TYPE_CHECK                                  128  ~3      !0
          5        BOOL_NOT                                         ~4      ~3
          6        BOOL                                             ~2      ~4
          7    > > JMPZ                                                     ~2, ->9
   20     8    > > RETURN                                                   !0
   22     9    >   TYPE_CHECK                                  256          !0
         10      > JMPZ                                                     ~5, ->15
   24    11    >   INIT_FCALL                                               'get_object_vars'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $6      
         14        ASSIGN                                                   !0, $6
   26    15    >   INIT_FCALL                                               'array_map'
         16        SEND_VAL                                                 'objectToArray'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $8      
         19      > RETURN                                                   $8
   27    20*     > RETURN                                                   null

End of function objecttoarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.56 ms | 1403 KiB | 20 Q