3v4l.org

run code in 500+ PHP versions simultaneously
<?php $json = '{ "id": 1, "label": "Beef", "sector_page_id": null, "value": 0, "tree_children": [ { "id": 46, "label": "Beef", "sector_page_id": null, "value": 0, "tree_children": [ { "id": 47, "label": "Beef - UK", "sector_page_id": null, "value": 15, "tree_children": [] }, { "id": 48, "label": "Beef - Europe", "sector_page_id": null, "value": 25, "tree_children": [] }, { "id": 49, "label": "Beef - Rest of World", "sector_page_id": null, "value": 0, "tree_children": [] } ] } ] }'; $obj = json_decode($json); function sum_recursive(object $obj): int { foreach ($obj->tree_children as $child) { $obj->value += sum_recursive($child); } return $obj->value; } sum_recursive($obj); var_export($obj);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6ZCYP
function name:  (null)
number of ops:  12
compiled vars:  !0 = $json, !1 = $obj
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%7B%0A++++%22id%22%3A+1%2C%0A++++%22label%22%3A+%22Beef%22%2C%0A++++%22sector_page_id%22%3A+null%2C%0A++++%22value%22%3A+0%2C%0A++++%22tree_children%22%3A+%5B%0A++++++++%7B%0A++++++++++++%22id%22%3A+46%2C%0A++++++++++++%22label%22%3A+%22Beef%22%2C%0A++++++++++++%22sector_page_id%22%3A+null%2C%0A++++++++++++%22value%22%3A+0%2C%0A++++++++++++%22tree_children%22%3A+%5B%0A++++++++++++++++%7B%0A++++++++++++++++++++%22id%22%3A+47%2C%0A++++++++++++++++++++%22label%22%3A+%22Beef+-+UK%22%2C%0A++++++++++++++++++++%22sector_page_id%22%3A+null%2C%0A++++++++++++++++++++%22value%22%3A+15%2C%0A++++++++++++++++++++%22tree_children%22%3A+%5B%5D%0A++++++++++++++++%7D%2C%0A++++++++++++++++%7B%0A++++++++++++++++++++%22id%22%3A+48%2C%0A++++++++++++++++++++%22label%22%3A+%22Beef+-+Europe%22%2C%0A++++++++++++++++++++%22sector_page_id%22%3A+null%2C%0A++++++++++++++++++++%22value%22%3A+25%2C%0A++++++++++++++++++++%22tree_children%22%3A+%5B%5D%0A++++++++++++++++%7D%2C%0A++++++++++++++++%7B%0A++++++++++++++++++++%22id%22%3A+49%2C%0A++++++++++++++++++++%22label%22%3A+%22Beef+-+Rest+of+World%22%2C%0A++++++++++++++++++++%22sector_page_id%22%3A+null%2C%0A++++++++++++++++++++%22value%22%3A+0%2C%0A++++++++++++++++++++%22tree_children%22%3A+%5B%5D%0A++++++++++++++++%7D%0A++++++++++++%5D%0A++++++++%7D%0A++++%5D%0A%7D'
   41     1        INIT_FCALL                                                   'json_decode'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                             $3      
          4        ASSIGN                                                       !1, $3
   50     5        INIT_FCALL                                                   'sum_recursive'
          6        SEND_VAR                                                     !1
          7        DO_FCALL                                          0          
   51     8        INIT_FCALL                                                   'var_export'
          9        SEND_VAR                                                     !1
         10        DO_ICALL                                                     
         11      > RETURN                                                       1

Function sum_recursive:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/6ZCYP
function name:  sum_recursive
number of ops:  16
compiled vars:  !0 = $obj, !1 = $child
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   43     0  E >   RECV                                                 !0      
   44     1        FETCH_OBJ_R                                          ~2      !0, 'tree_children'
          2      > FE_RESET_R                                           $3      ~2, ->10
          3    > > FE_FETCH_R                                                   $3, !1, ->10
   45     4    >   INIT_FCALL_BY_NAME                                           'sum_recursive'
          5        SEND_VAR_EX                                                  !1
          6        DO_FCALL                                          0  $5      
          7        ASSIGN_OBJ_OP                                     1          !0, 'value'
          8        OP_DATA                                                      $5
   44     9      > JMP                                                          ->3
         10    >   FE_FREE                                                      $3
   47    11        FETCH_OBJ_R                                          ~6      !0, 'value'
         12        VERIFY_RETURN_TYPE                                           ~6
         13      > RETURN                                                       ~6
   48    14*       VERIFY_RETURN_TYPE                                           
         15*     > RETURN                                                       null

End of function sum_recursive

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
169.19 ms | 2124 KiB | 16 Q