3v4l.org

run code in 300+ PHP versions simultaneously
<?php $r = array('hoge'=> new \stdClass()); $j = json_serialize($r); echo $j . "\n"; print_r(json_unserialize($j)); echo "\n"; function json_serialize($any) { return json_encode(json_wrap($any)); } function json_unserialize($str) { return json_unwrap(json_decode($str)); } function json_wrap($any, $skipAssoc = false) { if (!$skipAssoc && is_array($any) && is_string(key($any))) { return (object)array("_PHP_ASSOC" => json_wrap($any,true)); } if (is_array($any) || is_object($any)) { foreach ($any as &$v) { $v = json_wrap($v); } } return $any; } function json_unwrap($any, $skipAssoc = false) { if (!$skipAssoc && is_object($any) && is_object($any->_PHP_ASSOC) && count((array)$any) == 1) { return (array)json_unwrap($any->_PHP_ASSOC); } if (is_array($any) || is_object($any)) { foreach ($any as &$v) { $v = json_unwrap($v); } } return $any; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vZctd
function name:  (null)
number of ops:  18
compiled vars:  !0 = $r, !1 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   NEW                                              $2      'stdClass'
          1        DO_FCALL                                      0          
          2        INIT_ARRAY                                       ~4      $2, 'hoge'
          3        ASSIGN                                                   !0, ~4
    3     4        INIT_FCALL_BY_NAME                                       'json_serialize'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !1, $6
    4     8        CONCAT                                           ~8      !1, '%0A'
          9        ECHO                                                     ~8
    5    10        INIT_FCALL                                               'print_r'
         11        INIT_FCALL_BY_NAME                                       'json_unserialize'
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0  $9      
         14        SEND_VAR                                                 $9
         15        DO_ICALL                                                 
    6    16        ECHO                                                     '%0A'
   38    17      > RETURN                                                   1

Function json_serialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vZctd
function name:  json_serialize
number of ops:  9
compiled vars:  !0 = $any
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        INIT_FCALL                                               'json_encode'
          2        INIT_FCALL_BY_NAME                                       'json_wrap'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $1      
          5        SEND_VAR                                                 $1
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
   10     8*     > RETURN                                                   null

End of function json_serialize

Function json_unserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vZctd
function name:  json_unserialize
number of ops:  9
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        INIT_FCALL_BY_NAME                                       'json_unwrap'
          2        INIT_FCALL                                               'json_decode'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        SEND_VAR_NO_REF_EX                                       $1
          6        DO_FCALL                                      0  $2      
          7      > RETURN                                                   $2
   14     8*     > RETURN                                                   null

End of function json_unserialize

Function json_wrap:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 20
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 47) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 33
Branch analysis from position: 25
2 jumps found. (Code = 125) Position 1 = 26, Position 2 = 32
Branch analysis from position: 26
2 jumps found. (Code = 126) Position 1 = 27, Position 2 = 32
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
Branch analysis from position: 33
Branch analysis from position: 24
Branch analysis from position: 12
Branch analysis from position: 6
filename:       /in/vZctd
function name:  json_wrap
number of ops:  35
compiled vars:  !0 = $any, !1 = $skipAssoc, !2 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
   17     2        BOOL_NOT                                         ~3      !1
          3      > JMPZ_EX                                          ~3      ~3, ->6
          4    >   TYPE_CHECK                                  128  ~4      !0
          5        BOOL                                             ~3      ~4
          6    > > JMPZ_EX                                          ~3      ~3, ->12
          7    >   INIT_FCALL                                               'key'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $5      
         10        TYPE_CHECK                                   64  ~6      $5
         11        BOOL                                             ~3      ~6
         12    > > JMPZ                                                     ~3, ->20
   18    13    >   INIT_FCALL_BY_NAME                                       'json_wrap'
         14        SEND_VAR_EX                                              !0
         15        SEND_VAL_EX                                              <true>
         16        DO_FCALL                                      0  $7      
         17        INIT_ARRAY                                       ~8      $7, '_PHP_ASSOC'
         18        CAST                                          8  ~9      ~8
         19      > RETURN                                                   ~9
   20    20    >   TYPE_CHECK                                  128  ~10     !0
         21      > JMPNZ_EX                                         ~10     ~10, ->24
         22    >   TYPE_CHECK                                  256  ~11     !0
         23        BOOL                                             ~10     ~11
         24    > > JMPZ                                                     ~10, ->33
   21    25    > > FE_RESET_RW                                      $12     !0, ->32
         26    > > FE_FETCH_RW                                              $12, !2, ->32
   22    27    >   INIT_FCALL_BY_NAME                                       'json_wrap'
         28        SEND_VAR_EX                                              !2
         29        DO_FCALL                                      0  $13     
         30        ASSIGN                                                   !2, $13
   21    31      > JMP                                                      ->26
         32    >   FE_FREE                                                  $12
   25    33    > > RETURN                                                   !0
   26    34*     > RETURN                                                   null

End of function json_wrap

Function json_unwrap:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 23
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
2 jumps found. (Code = 47) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 36
Branch analysis from position: 28
2 jumps found. (Code = 125) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
2 jumps found. (Code = 126) Position 1 = 30, Position 2 = 35
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 36
Branch analysis from position: 27
Branch analysis from position: 15
Branch analysis from position: 10
Branch analysis from position: 6
filename:       /in/vZctd
function name:  json_unwrap
number of ops:  38
compiled vars:  !0 = $any, !1 = $skipAssoc, !2 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
   29     2        BOOL_NOT                                         ~3      !1
          3      > JMPZ_EX                                          ~3      ~3, ->6
          4    >   TYPE_CHECK                                  256  ~4      !0
          5        BOOL                                             ~3      ~4
          6    > > JMPZ_EX                                          ~3      ~3, ->10
          7    >   FETCH_OBJ_R                                      ~5      !0, '_PHP_ASSOC'
          8        TYPE_CHECK                                  256  ~6      ~5
          9        BOOL                                             ~3      ~6
         10    > > JMPZ_EX                                          ~3      ~3, ->15
         11    >   CAST                                          7  ~7      !0
         12        COUNT                                            ~8      ~7
         13        IS_EQUAL                                         ~9      ~8, 1
         14        BOOL                                             ~3      ~9
         15    > > JMPZ                                                     ~3, ->23
   30    16    >   INIT_FCALL_BY_NAME                                       'json_unwrap'
         17        CHECK_FUNC_ARG                                           
         18        FETCH_OBJ_FUNC_ARG                               $10     !0, '_PHP_ASSOC'
         19        SEND_FUNC_ARG                                            $10
         20        DO_FCALL                                      0  $11     
         21        CAST                                          7  ~12     $11
         22      > RETURN                                                   ~12
   32    23    >   TYPE_CHECK                                  128  ~13     !0
         24      > JMPNZ_EX                                         ~13     ~13, ->27
         25    >   TYPE_CHECK                                  256  ~14     !0
         26        BOOL                                             ~13     ~14
         27    > > JMPZ                                                     ~13, ->36
   33    28    > > FE_RESET_RW                                      $15     !0, ->35
         29    > > FE_FETCH_RW                                              $15, !2, ->35
   34    30    >   INIT_FCALL_BY_NAME                                       'json_unwrap'
         31        SEND_VAR_EX                                              !2
         32        DO_FCALL                                      0  $16     
         33        ASSIGN                                                   !2, $16
   33    34      > JMP                                                      ->29
         35    >   FE_FREE                                                  $15
   37    36    > > RETURN                                                   !0
   38    37*     > RETURN                                                   null

End of function json_unwrap

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.5 ms | 1400 KiB | 21 Q