3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('json_encode')) { function json_encode($it) { if (!($is_arr = is_array($it)) && !is_object($it)) { return _js_enc_value($it); } $assoc = false; $i = 0; foreach ($it as $k => $v) { if ($k !== $i) { $assoc = true; break; } $i++; } if (!$is_arr) { $assoc = true; } $data = array(); foreach ($it as $k => $v) { $k = '"'. addcslashes($k, '"\\') . '"'; $v = _js_enc_value($v); $data[] = $assoc ? $k . ':' . $v : $v; } if ($assoc) { $spl = '{'; $spr = '}'; } else { $spl = '['; $spr = ']'; } return $spl . implode(',', $data) . $spr; } function _js_enc_value($value) { switch (true) { case is_array($value): case is_object($value): return json_encode($value); case is_bool($value): return $value ? 'true' : 'false'; case $value === null: case is_resource($value): return 'null'; case is_string($value): return '"' . _js_uc_esc($value) . '"'; default: return $value; } } function _js_uc_esc($value) { $pattern = "/\r|(\n)|((?:[^\x09\x0A\x0D\x20-\x7E]{3})+)/"; return preg_replace_callback($pattern, '_js_uc_esc_cb', $value); } function _js_uc_esc_cb($matches) { switch (true) { case isset($matches[2]): $char = mb_convert_encoding($matches[2], 'UTF-16', 'UTF-8'); $str = ''; $len = strlen($char); for ($i = 0; $i < $len; $i += 2) { $str .= sprintf('\\u%02x%02x', ord($char[$i]), ord($char[$i + 1])); } return $str; case isset($matches[1]): return '\\n'; default: return '\\r'; } } } $var = array( 0 => array('text', 1, 1.1, true, false, null, array(), new stdClass, fopen('php://stdout', 'r')), 2 => array('a' => 'hoge', 'b' => 'foo'), ); echo @json_encode($var);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/APMp5
function name:  (null)
number of ops:  34
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'function_exists'
          1        SEND_VAL                                                 'json_encode'
          2        DO_ICALL                                         $1      
          3        BOOL_NOT                                         ~2      $1
          4      > JMPZ                                                     ~2, ->9
    5     5    >   DECLARE_FUNCTION                                         'json_encode'
   37     6        DECLARE_FUNCTION                                         '_js_enc_value'
   54     7        DECLARE_FUNCTION                                         '_js_uc_esc'
   59     8        DECLARE_FUNCTION                                         '_js_uc_esc_cb'
   79     9    >   INIT_ARRAY                                       ~3      'text'
         10        ADD_ARRAY_ELEMENT                                ~3      1
         11        ADD_ARRAY_ELEMENT                                ~3      1.1
         12        ADD_ARRAY_ELEMENT                                ~3      <true>
         13        ADD_ARRAY_ELEMENT                                ~3      <false>
         14        ADD_ARRAY_ELEMENT                                ~3      null
         15        ADD_ARRAY_ELEMENT                                ~3      <array>
         16        NEW                                              $4      'stdClass'
         17        DO_FCALL                                      0          
         18        ADD_ARRAY_ELEMENT                                ~3      $4
         19        INIT_FCALL                                               'fopen'
         20        SEND_VAL                                                 'php%3A%2F%2Fstdout'
         21        SEND_VAL                                                 'r'
         22        DO_ICALL                                         $6      
         23        ADD_ARRAY_ELEMENT                                ~3      $6
         24        INIT_ARRAY                                       ~7      ~3, 0
         25        ADD_ARRAY_ELEMENT                                ~7      <array>, 2
   78    26        ASSIGN                                                   !0, ~7
   83    27        BEGIN_SILENCE                                    ~9      
         28        INIT_FCALL                                               'json_encode'
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                         $10     
         31        END_SILENCE                                              ~9
         32        ECHO                                                     $10
         33      > RETURN                                                   1

Function %00json_encode%2Fin%2FAPMp5%3A5%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 52
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 52
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 48
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 57
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
Branch analysis from position: 28
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 24
Branch analysis from position: 24
Branch analysis from position: 8
filename:       /in/APMp5
function name:  json_encode
number of ops:  67
compiled vars:  !0 = $it, !1 = $is_arr, !2 = $assoc, !3 = $i, !4 = $v, !5 = $k, !6 = $data, !7 = $spl, !8 = $spr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        TYPE_CHECK                                  128  ~9      !0
          2        ASSIGN                                           ~10     !1, ~9
          3        BOOL_NOT                                         ~11     ~10
          4      > JMPZ_EX                                          ~11     ~11, ->8
          5    >   TYPE_CHECK                                  256  ~12     !0
          6        BOOL_NOT                                         ~13     ~12
          7        BOOL                                             ~11     ~13
          8    > > JMPZ                                                     ~11, ->13
    7     9    >   INIT_FCALL_BY_NAME                                       '_js_enc_value'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $14     
         12      > RETURN                                                   $14
    9    13    >   ASSIGN                                                   !2, <false>
   10    14        ASSIGN                                                   !3, 0
   11    15      > FE_RESET_R                                       $17     !0, ->24
         16    > > FE_FETCH_R                                       ~18     $17, !4, ->24
         17    >   ASSIGN                                                   !5, ~18
   12    18        IS_NOT_IDENTICAL                                         !5, !3
         19      > JMPZ                                                     ~20, ->22
   13    20    >   ASSIGN                                                   !2, <true>
   14    21      > JMP                                                      ->24
   16    22    >   PRE_INC                                                  !3
   11    23      > JMP                                                      ->16
         24    >   FE_FREE                                                  $17
   18    25        BOOL_NOT                                         ~23     !1
         26      > JMPZ                                                     ~23, ->28
   19    27    >   ASSIGN                                                   !2, <true>
   21    28    >   ASSIGN                                                   !6, <array>
   22    29      > FE_RESET_R                                       $26     !0, ->52
         30    > > FE_FETCH_R                                       ~27     $26, !4, ->52
         31    >   ASSIGN                                                   !5, ~27
   23    32        INIT_FCALL                                               'addcslashes'
         33        SEND_VAR                                                 !5
         34        SEND_VAL                                                 '%22%5C'
         35        DO_ICALL                                         $29     
         36        CONCAT                                           ~30     '%22', $29
         37        CONCAT                                           ~31     ~30, '%22'
         38        ASSIGN                                                   !5, ~31
   24    39        INIT_FCALL_BY_NAME                                       '_js_enc_value'
         40        SEND_VAR_EX                                              !4
         41        DO_FCALL                                      0  $33     
         42        ASSIGN                                                   !4, $33
   25    43      > JMPZ                                                     !2, ->48
         44    >   CONCAT                                           ~36     !5, '%3A'
         45        CONCAT                                           ~37     ~36, !4
         46        QM_ASSIGN                                        ~38     ~37
         47      > JMP                                                      ->49
         48    >   QM_ASSIGN                                        ~38     !4
         49    >   ASSIGN_DIM                                               !6
         50        OP_DATA                                                  ~38
   22    51      > JMP                                                      ->30
         52    >   FE_FREE                                                  $26
   27    53      > JMPZ                                                     !2, ->57
   28    54    >   ASSIGN                                                   !7, '%7B'
   29    55        ASSIGN                                                   !8, '%7D'
         56      > JMP                                                      ->59
   31    57    >   ASSIGN                                                   !7, '%5B'
   32    58        ASSIGN                                                   !8, '%5D'
   34    59    >   INIT_FCALL                                               'implode'
         60        SEND_VAL                                                 '%2C'
         61        SEND_VAR                                                 !6
         62        DO_ICALL                                         $43     
         63        CONCAT                                           ~44     !7, $43
         64        CONCAT                                           ~45     ~44, !8
         65      > RETURN                                                   ~45
   35    66*     > RETURN                                                   null

End of function %00json_encode%2Fin%2FAPMp5%3A5%240

Function %00_js_enc_value%2Fin%2FAPMp5%3A37%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 18
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 23
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 23
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 24
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/APMp5
function name:  _js_enc_value
number of ops:  32
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   39     1        TYPE_CHECK                                  128          !0
          2      > JMPNZ                                                    ~2, ->14
   40     3    >   TYPE_CHECK                                  256          !0
          4      > JMPNZ                                                    ~3, ->14
   42     5    >   TYPE_CHECK                                   12          !0
          6      > JMPNZ                                                    ~4, ->18
   44     7    >   TYPE_CHECK                                    2          !0
          8      > JMPNZ                                                    ~5, ->23
   45     9    >   TYPE_CHECK                                  512          !0
         10      > JMPNZ                                                    ~6, ->23
   47    11    >   TYPE_CHECK                                   64          !0
         12      > JMPNZ                                                    ~7, ->24
         13    > > JMP                                                      ->30
   41    14    >   INIT_FCALL                                               'json_encode'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $8      
         17      > RETURN                                                   $8
   43    18    > > JMPZ                                                     !0, ->21
         19    >   QM_ASSIGN                                        ~9      'true'
         20      > JMP                                                      ->22
         21    >   QM_ASSIGN                                        ~9      'false'
         22    > > RETURN                                                   ~9
   46    23    > > RETURN                                                   'null'
   48    24    >   INIT_FCALL_BY_NAME                                       '_js_uc_esc'
         25        SEND_VAR_EX                                              !0
         26        DO_FCALL                                      0  $10     
         27        CONCAT                                           ~11     '%22', $10
         28        CONCAT                                           ~12     ~11, '%22'
         29      > RETURN                                                   ~12
   50    30    > > RETURN                                                   !0
   52    31*     > RETURN                                                   null

End of function %00_js_enc_value%2Fin%2FAPMp5%3A37%241

Function %00_js_uc_esc%2Fin%2FAPMp5%3A54%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/APMp5
function name:  _js_uc_esc
number of ops:  9
compiled vars:  !0 = $value, !1 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
   55     1        ASSIGN                                                   !1, '%2F%0D%7C%28%0A%29%7C%28%28%3F%3A%5B%5E%09%0A%0D+-%7E%5D%7B3%7D%29%2B%29%2F'
   56     2        INIT_FCALL                                               'preg_replace_callback'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 '_js_uc_esc_cb'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7      > RETURN                                                   $3
   57     8*     > RETURN                                                   null

End of function %00_js_uc_esc%2Fin%2FAPMp5%3A54%242

Function %00_js_uc_esc_cb%2Fin%2FAPMp5%3A59%243:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 37
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 18
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 18
Branch analysis from position: 36
Branch analysis from position: 18
filename:       /in/APMp5
function name:  _js_uc_esc_cb
number of ops:  40
compiled vars:  !0 = $matches, !1 = $char, !2 = $str, !3 = $len, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
   61     1        ISSET_ISEMPTY_DIM_OBJ                         0          !0, 2
          2      > JMPNZ                                                    ~6, ->6
   69     3    >   ISSET_ISEMPTY_DIM_OBJ                         0          !0, 1
          4      > JMPNZ                                                    ~7, ->37
          5    > > JMP                                                      ->38
   62     6    >   INIT_FCALL                                               'mb_convert_encoding'
          7        FETCH_DIM_R                                      ~8      !0, 2
          8        SEND_VAL                                                 ~8
          9        SEND_VAL                                                 'UTF-16'
         10        SEND_VAL                                                 'UTF-8'
         11        DO_ICALL                                         $9      
         12        ASSIGN                                                   !1, $9
   63    13        ASSIGN                                                   !2, ''
   64    14        STRLEN                                           ~12     !1
         15        ASSIGN                                                   !3, ~12
   65    16        ASSIGN                                                   !4, 0
         17      > JMP                                                      ->34
   66    18    >   INIT_FCALL                                               'sprintf'
         19        SEND_VAL                                                 '%5Cu%2502x%2502x'
         20        INIT_FCALL                                               'ord'
         21        FETCH_DIM_R                                      ~15     !1, !4
         22        SEND_VAL                                                 ~15
         23        DO_ICALL                                         $16     
         24        SEND_VAR                                                 $16
         25        INIT_FCALL                                               'ord'
         26        ADD                                              ~17     !4, 1
         27        FETCH_DIM_R                                      ~18     !1, ~17
         28        SEND_VAL                                                 ~18
         29        DO_ICALL                                         $19     
         30        SEND_VAR                                                 $19
         31        DO_ICALL                                         $20     
         32        ASSIGN_OP                                     8          !2, $20
   65    33        ASSIGN_OP                                     1          !4, 2
         34    >   IS_SMALLER                                               !4, !3
         35      > JMPNZ                                                    ~23, ->18
   68    36    > > RETURN                                                   !2
   70    37    > > RETURN                                                   '%5Cn'
   72    38    > > RETURN                                                   '%5Cr'
   74    39*     > RETURN                                                   null

End of function %00_js_uc_esc_cb%2Fin%2FAPMp5%3A59%243

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.2 ms | 1408 KiB | 31 Q