3v4l.org

run code in 300+ PHP versions simultaneously
<?php $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'; // 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; } } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DL0Bn
function name:  (null)
number of ops:  32
compiled vars:  !0 = $employee_obj, !1 = $my_json
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        ASSIGN_OBJ                                               !0, 'name'
          4        OP_DATA                                                  'Jamy+Jo'
    5     5        ASSIGN_OBJ                                               !0, 'age'
          6        OP_DATA                                                  58
    7     7        FETCH_OBJ_W                                      $7      !0, 'address'
          8        ASSIGN_OBJ                                               $7, 'apartment'
          9        OP_DATA                                                  '240'
    8    10        FETCH_OBJ_W                                      $9      !0, 'address'
         11        ASSIGN_OBJ                                               $9, 'state'
         12        OP_DATA                                                  'Tx'
    9    13        FETCH_OBJ_W                                      $11     !0, 'address'
         14        ASSIGN_OBJ                                               $11, 'city'
         15        OP_DATA                                                  'Houston'
   10    16        FETCH_OBJ_W                                      $13     !0, 'address'
         17        ASSIGN_OBJ                                               $13, 'zip'
         18        OP_DATA                                                  '77300'
   11    19        ASSIGN_OBJ                                               !0, 'role'
         20        OP_DATA                                                  'PHP+Developer'
   14    21        INIT_FCALL                                               'json_encode'
         22        INIT_FCALL_BY_NAME                                       'objectToArray'
         23        SEND_VAR_EX                                              !0
         24        DO_FCALL                                      0  $16     
         25        SEND_VAR                                                 $16
         26        DO_ICALL                                         $17     
         27        ASSIGN                                                   !1, $17
   16    28        INIT_FCALL                                               'print_r'
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                                 
   32    31      > 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/DL0Bn
function name:  objectToArray
number of ops:  17
compiled vars:  !0 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        TYPE_CHECK                                  256          !0
          2      > JMPZ                                                     ~1, ->7
   22     3    >   INIT_FCALL                                               'get_object_vars'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        ASSIGN                                                   !0, $2
   25     7    >   TYPE_CHECK                                  128          !0
          8      > JMPZ                                                     ~4, ->15
   26     9    >   INIT_FCALL                                               'array_map'
         10        SEND_VAL                                                 'objectToArray'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $5      
         13      > RETURN                                                   $5
         14*       JMP                                                      ->16
   29    15    > > RETURN                                                   !0
   31    16*     > RETURN                                                   null

End of function objecttoarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.78 ms | 1400 KiB | 21 Q