3v4l.org

run code in 300+ PHP versions simultaneously
<?php // convert to json data $my_json = json_encode(objectToArray($employee_obj)); print_r($my_json); function objectToArray($d) { if (is_object($d)) { // Gets the properties of the object $d = get_object_vars($d); } if (is_array($d)) { return array_map(__FUNCTION__, $d); } else { // Return array return $d; } } $employee_obj = new stdClass(); $employee_obj->name = 'Jamy Jo'; $employee_obj->age = 58; $employee_obj->address->street = '240 Lake Rd'; $employee_obj->address->apartment = '240'; $employee_obj->address->state = 'Tx'; $employee_obj->address->city = 'Houston'; $employee_obj->address->zip = '77300'; $employee_obj->role = 'PHP Developer'; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WiME1
function name:  (null)
number of ops:  35
compiled vars:  !0 = $my_json, !1 = $employee_obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'json_encode'
          1        INIT_FCALL_BY_NAME                                       'objectToArray'
          2        SEND_VAR_EX                                              !1
          3        DO_FCALL                                      0  $2      
          4        SEND_VAR                                                 $2
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !0, $3
    6     7        INIT_FCALL                                               'print_r'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                                 
   23    10        NEW                                              $6      'stdClass'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !1, $6
   24    13        ASSIGN_OBJ                                               !1, 'name'
         14        OP_DATA                                                  'Jamy+Jo'
   25    15        ASSIGN_OBJ                                               !1, 'age'
         16        OP_DATA                                                  58
   26    17        FETCH_OBJ_W                                      $11     !1, 'address'
         18        ASSIGN_OBJ                                               $11, 'street'
         19        OP_DATA                                                  '240+Lake+Rd'
   27    20        FETCH_OBJ_W                                      $13     !1, 'address'
         21        ASSIGN_OBJ                                               $13, 'apartment'
         22        OP_DATA                                                  '240'
   28    23        FETCH_OBJ_W                                      $15     !1, 'address'
         24        ASSIGN_OBJ                                               $15, 'state'
         25        OP_DATA                                                  'Tx'
   29    26        FETCH_OBJ_W                                      $17     !1, 'address'
         27        ASSIGN_OBJ                                               $17, 'city'
         28        OP_DATA                                                  'Houston'
   30    29        FETCH_OBJ_W                                      $19     !1, 'address'
         30        ASSIGN_OBJ                                               $19, 'zip'
         31        OP_DATA                                                  '77300'
   31    32        ASSIGN_OBJ                                               !1, 'role'
         33        OP_DATA                                                  'PHP+Developer'
   32    34      > RETURN                                                   1

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

End of function objecttoarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.81 ms | 1400 KiB | 21 Q