3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ObjectToArrayConverter { /** * @param mixed $value * * @raturn array */ public static function toArray($value) { if (! (is_object($value) || is_array($value))) { return $value; } if (is_object($value) && method_exists($value, '__toArray')) { return $value->__toArray(); } array_map(__METHOD__, (array) $value); } } $obj1 = new stdClass(); $obj2 = new stdClass(); $obj1->foo = 'foo'; $obj1->someArr = []; $obj1->obj2 = $obj2; $obj2->bar = 'bar'; var_dump(ObjectToArrayConverter::toArray($obj1));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YH50n
function name:  (null)
number of ops:  21
compiled vars:  !0 = $obj1, !1 = $obj2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   NEW                                              $2      'stdClass'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   24     3        NEW                                              $5      'stdClass'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   25     6        ASSIGN_OBJ                                               !0, 'foo'
          7        OP_DATA                                                  'foo'
   26     8        ASSIGN_OBJ                                               !0, 'someArr'
          9        OP_DATA                                                  <array>
   27    10        ASSIGN_OBJ                                               !0, 'obj2'
         11        OP_DATA                                                  !1
   28    12        ASSIGN_OBJ                                               !1, 'bar'
         13        OP_DATA                                                  'bar'
   30    14        INIT_FCALL                                               'var_dump'
         15        INIT_STATIC_METHOD_CALL                                  'ObjectToArrayConverter', 'toArray'
         16        SEND_VAR                                                 !0
         17        DO_FCALL                                      0  $12     
         18        SEND_VAR                                                 $12
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Class ObjectToArrayConverter:
Function toarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 5
filename:       /in/YH50n
function name:  toArray
number of ops:  25
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        TYPE_CHECK                                  256  ~1      !0
          2      > JMPNZ_EX                                         ~1      ~1, ->5
          3    >   TYPE_CHECK                                  128  ~2      !0
          4        BOOL                                             ~1      ~2
          5    >   BOOL_NOT                                         ~3      ~1
          6      > JMPZ                                                     ~3, ->8
   13     7    > > RETURN                                                   !0
   16     8    >   TYPE_CHECK                                  256  ~4      !0
          9      > JMPZ_EX                                          ~4      ~4, ->15
         10    >   INIT_FCALL                                               'method_exists'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 '__toArray'
         13        DO_ICALL                                         $5      
         14        BOOL                                             ~4      $5
         15    > > JMPZ                                                     ~4, ->19
   17    16    >   INIT_METHOD_CALL                                         !0, '__toArray'
         17        DO_FCALL                                      0  $6      
         18      > RETURN                                                   $6
   19    19    >   INIT_FCALL                                               'array_map'
         20        SEND_VAL                                                 'ObjectToArrayConverter%3A%3AtoArray'
         21        CAST                                          7  ~7      !0
         22        SEND_VAL                                                 ~7
         23        DO_ICALL                                                 
   20    24      > RETURN                                                   null

End of function toarray

End of class ObjectToArrayConverter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.05 ms | 1400 KiB | 19 Q