3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @throws JsonException */ function alterJson(string $json): string { $data = json_decode($json, false, 512, JSON_THROW_ON_ERROR); if (empty($data->expire_user_id)) { return '{}'; } $data->expire_user_id = explode(',', $data->expire_user_id); $data->user_id = array_shift($data->expire_user_id); if ($data->expire_user_id) { $data->expire_user_id = implode(',', $data->expire_user_id); } else { unset($data->expire_user_id); } return json_encode($data, JSON_THROW_ON_ERROR); } echo alterJson(<<<JSON {"user_id":3,"created_at":"2020-10-05 04:59:05","expire_user_id":"2,1"} JSON), PHP_EOL; echo alterJson(<<<JSON {"user_id":3,"created_at":"2020-10-05 04:59:05","expire_user_id":"1"} JSON), PHP_EOL; echo alterJson(<<<JSON {"user_id":3,"created_at":"2020-10-05 04:59:05"} JSON), PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5HESp
function name:  (null)
number of ops:  16
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                               'alterjson'
   27     1        SEND_VAL                                                 '++++%7B%22user_id%22%3A3%2C%22created_at%22%3A%222020-10-05+04%3A59%3A05%22%2C%22expire_user_id%22%3A%222%2C1%22%7D'
   26     2        DO_FCALL                                      0  $0      
   27     3        ECHO                                                     $0
   28     4        ECHO                                                     '%0A'
   30     5        INIT_FCALL                                               'alterjson'
   31     6        SEND_VAL                                                 '++++%7B%22user_id%22%3A3%2C%22created_at%22%3A%222020-10-05+04%3A59%3A05%22%2C%22expire_user_id%22%3A%221%22%7D'
   30     7        DO_FCALL                                      0  $1      
   31     8        ECHO                                                     $1
   32     9        ECHO                                                     '%0A'
   34    10        INIT_FCALL                                               'alterjson'
   35    11        SEND_VAL                                                 '++++%7B%22user_id%22%3A3%2C%22created_at%22%3A%222020-10-05+04%3A59%3A05%22%7D'
   34    12        DO_FCALL                                      0  $2      
   35    13        ECHO                                                     $2
   36    14        ECHO                                                     '%0A'
   37    15      > RETURN                                                   1

Function alterjson:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 34
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5HESp
function name:  alterJson
number of ops:  43
compiled vars:  !0 = $json, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <false>
          4        SEND_VAL                                                 512
          5        SEND_VAL                                                 4194304
          6        DO_ICALL                                         $2      
          7        ASSIGN                                                   !1, $2
   10     8        ISSET_ISEMPTY_PROP_OBJ                                   !1, 'expire_user_id'
          9      > JMPZ                                                     ~4, ->11
   11    10    > > RETURN                                                   '%7B%7D'
   14    11    >   INIT_FCALL                                               'explode'
         12        SEND_VAL                                                 '%2C'
         13        FETCH_OBJ_R                                      ~6      !1, 'expire_user_id'
         14        SEND_VAL                                                 ~6
         15        DO_ICALL                                         $7      
         16        ASSIGN_OBJ                                               !1, 'expire_user_id'
         17        OP_DATA                                                  $7
   15    18        INIT_FCALL                                               'array_shift'
         19        FETCH_OBJ_W                                      $9      !1, 'expire_user_id'
         20        SEND_REF                                                 $9
         21        DO_ICALL                                         $10     
         22        ASSIGN_OBJ                                               !1, 'user_id'
         23        OP_DATA                                                  $10
   17    24        FETCH_OBJ_R                                      ~11     !1, 'expire_user_id'
         25      > JMPZ                                                     ~11, ->34
   18    26    >   INIT_FCALL                                               'implode'
         27        SEND_VAL                                                 '%2C'
         28        FETCH_OBJ_R                                      ~13     !1, 'expire_user_id'
         29        SEND_VAL                                                 ~13
         30        DO_ICALL                                         $14     
         31        ASSIGN_OBJ                                               !1, 'expire_user_id'
         32        OP_DATA                                                  $14
   17    33      > JMP                                                      ->35
   20    34    >   UNSET_OBJ                                                !1, 'expire_user_id'
   23    35    >   INIT_FCALL                                               'json_encode'
         36        SEND_VAR                                                 !1
         37        SEND_VAL                                                 4194304
         38        DO_ICALL                                         $15     
         39        VERIFY_RETURN_TYPE                                       $15
         40      > RETURN                                                   $15
   24    41*       VERIFY_RETURN_TYPE                                       
         42*     > RETURN                                                   null

End of function alterjson

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.63 ms | 1022 KiB | 21 Q