3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('json_encode')) { function json_encode($it) { $tmp = $it; if (!mb_convert_variables($tmp, 'UTF-8', 'UTF-8')) { return false; } if (!($assoc = is_object($it)) && !is_array($it)) { return _js_enc_value($it); } $i = 0; $it = (array)$it; if (!$assoc) { foreach ($it as $k => $v) { if ($k !== $i) { $assoc = true; break; } $i++; } } $data = array(); foreach ($it as $k => $v) { $v = _js_enc_value($v); if ($assoc) { $k = _js_enc_value($k); $data[] = $k . ':' . $v; } else { $data[] = $v; } } if ($assoc) { $bl = '{'; $br = '}'; } else { $bl = '['; $br = ']'; } return $bl . implode(',', $data) . $br; } 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) && _js_error(): return 'null'; case is_string($value): return _js_uc_esc($value); default: return $value; } } function _js_error() { return trigger_error( 'json_encode(): type is unsupported, encoded as null', E_USER_WARNING ); } function _js_uc_esc($value) { $pattern = "@[\x08-\x10\x0c\x0d\\\\\"/]|([^\x08-\x10\x0c\x0d\x32-\x7f\\\\\"/])++@"; return '"' . preg_replace_callback($pattern, '_js_uc_esc_cb', $value) . '"'; } function _js_uc_esc_cb($matches) { switch (true) { case isset($matches[1]): $char = mb_convert_encoding($matches[0], '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; default: return addcslashes($matches[0], "\x08\x09\x10\x0c\x0d\\\"/"); } } } $str = ''; for ($i=0;$i<=300;$i++) { $str .= chr($i); } $str .= chr(127); var_dump(json_encode(array("test" => $str)));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 13
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 13
Branch analysis from position: 20
Branch analysis from position: 13
Branch analysis from position: 10
filename:       /in/LSONn
function name:  (null)
number of ops:  29
compiled vars:  !0 = $str, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'function_exists'
          1        SEND_VAL                                                 'json_encode'
          2        DO_ICALL                                         $2      
          3        BOOL_NOT                                         ~3      $2
          4      > JMPZ                                                     ~3, ->10
    5     5    >   DECLARE_FUNCTION                                         'json_encode'
   44     6        DECLARE_FUNCTION                                         '_js_enc_value'
   61     7        DECLARE_FUNCTION                                         '_js_error'
   68     8        DECLARE_FUNCTION                                         '_js_uc_esc'
   73     9        DECLARE_FUNCTION                                         '_js_uc_esc_cb'
   93    10    >   ASSIGN                                                   !0, ''
   94    11        ASSIGN                                                   !1, 0
         12      > JMP                                                      ->18
   95    13    >   INIT_FCALL                                               'chr'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $6      
         16        ASSIGN_OP                                     8          !0, $6
   94    17        PRE_INC                                                  !1
         18    >   IS_SMALLER_OR_EQUAL                                      !1, 300
         19      > JMPNZ                                                    ~9, ->13
   97    20    >   ASSIGN_OP                                     8          !0, '%7F'
   98    21        INIT_FCALL                                               'var_dump'
         22        INIT_FCALL                                               'json_encode'
         23        INIT_ARRAY                                       ~11     !0, 'test'
         24        SEND_VAL                                                 ~11
         25        DO_ICALL                                         $12     
         26        SEND_VAR                                                 $12
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

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

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

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

End of function %00_js_enc_value%2Fin%2FLSONn%3A44%241

Function %00_js_error%2Fin%2FLSONn%3A61%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LSONn
function name:  _js_error
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   INIT_FCALL                                               'trigger_error'
   63     1        SEND_VAL                                                 'json_encode%28%29%3A+type+is+unsupported%2C+encoded+as+null'
   64     2        SEND_VAL                                                 512
          3        DO_ICALL                                         $0      
          4      > RETURN                                                   $0
   66     5*     > RETURN                                                   null

End of function %00_js_error%2Fin%2FLSONn%3A61%242

Function %00_js_uc_esc%2Fin%2FLSONn%3A68%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LSONn
function name:  _js_uc_esc
number of ops:  11
compiled vars:  !0 = $value, !1 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   RECV                                             !0      
   69     1        ASSIGN                                                   !1, '%40%5B%08-%10%0C%0D%5C%5C%22%2F%5D%7C%28%5B%5E%08-%10%0C%0D2-%7F%5C%5C%22%2F%5D%29%2B%2B%40'
   70     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        CONCAT                                           ~4      '%22', $3
          8        CONCAT                                           ~5      ~4, '%22'
          9      > RETURN                                                   ~5
   71    10*     > RETURN                                                   null

End of function %00_js_uc_esc%2Fin%2FLSONn%3A68%243

Function %00_js_uc_esc_cb%2Fin%2FLSONn%3A73%244:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
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: 4
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 16
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 16
Branch analysis from position: 34
Branch analysis from position: 16
filename:       /in/LSONn
function name:  _js_uc_esc_cb
number of ops:  42
compiled vars:  !0 = $matches, !1 = $char, !2 = $str, !3 = $len, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   RECV                                             !0      
   75     1        ISSET_ISEMPTY_DIM_OBJ                         0          !0, 1
          2      > JMPNZ                                                    ~6, ->4
          3    > > JMP                                                      ->35
   76     4    >   INIT_FCALL                                               'mb_convert_encoding'
          5        FETCH_DIM_R                                      ~7      !0, 0
          6        SEND_VAL                                                 ~7
          7        SEND_VAL                                                 'UTF-16'
          8        SEND_VAL                                                 'UTF-8'
          9        DO_ICALL                                         $8      
         10        ASSIGN                                                   !1, $8
   77    11        ASSIGN                                                   !2, ''
   78    12        STRLEN                                           ~11     !1
         13        ASSIGN                                                   !3, ~11
   79    14        ASSIGN                                                   !4, 0
         15      > JMP                                                      ->32
   80    16    >   INIT_FCALL                                               'sprintf'
         17        SEND_VAL                                                 '%5Cu%2502x%2502x'
   81    18        INIT_FCALL                                               'ord'
         19        FETCH_DIM_R                                      ~14     !1, !4
         20        SEND_VAL                                                 ~14
         21        DO_ICALL                                         $15     
         22        SEND_VAR                                                 $15
   82    23        INIT_FCALL                                               'ord'
         24        ADD                                              ~16     !4, 1
         25        FETCH_DIM_R                                      ~17     !1, ~16
         26        SEND_VAL                                                 ~17
         27        DO_ICALL                                         $18     
         28        SEND_VAR                                                 $18
         29        DO_ICALL                                         $19     
         30        ASSIGN_OP                                     8          !2, $19
   79    31        ASSIGN_OP                                     1          !4, 2
         32    >   IS_SMALLER                                               !4, !3
         33      > JMPNZ                                                    ~22, ->16
   85    34    > > RETURN                                                   !2
   87    35    >   INIT_FCALL                                               'addcslashes'
         36        FETCH_DIM_R                                      ~23     !0, 0
         37        SEND_VAL                                                 ~23
         38        SEND_VAL                                                 '%08%09%10%0C%0D%5C%22%2F'
         39        DO_ICALL                                         $24     
         40      > RETURN                                                   $24
   89    41*     > RETURN                                                   null

End of function %00_js_uc_esc_cb%2Fin%2FLSONn%3A73%244

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.2 ms | 1416 KiB | 37 Q