3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('json_encode')) { function json_encode($it) { 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) { if ($value !== @mb_convert_encoding("UTF-8", "UTF-8", $value)) { return 'null'; } $pattern = "@[\x08-x010\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/tDdPO
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'
   40     6        DECLARE_FUNCTION                                         '_js_enc_value'
   57     7        DECLARE_FUNCTION                                         '_js_error'
   64     8        DECLARE_FUNCTION                                         '_js_uc_esc'
   72     9        DECLARE_FUNCTION                                         '_js_uc_esc_cb'
   92    10    >   ASSIGN                                                   !0, ''
   93    11        ASSIGN                                                   !1, 0
         12      > JMP                                                      ->18
   94    13    >   INIT_FCALL                                               'chr'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $6      
         16        ASSIGN_OP                                     8          !0, $6
   93    17        PRE_INC                                                  !1
         18    >   IS_SMALLER_OR_EQUAL                                      !1, 300
         19      > JMPNZ                                                    ~9, ->13
   96    20    >   ASSIGN_OP                                     8          !0, '%7F'
   97    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%2FtDdPO%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 = 43) Position 1 = 18, Position 2 = 28
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 27
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 27
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 49
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 49
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 46
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 54
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 27
Branch analysis from position: 27
Branch analysis from position: 28
Branch analysis from position: 8
filename:       /in/tDdPO
function name:  json_encode
number of ops:  64
compiled vars:  !0 = $it, !1 = $assoc, !2 = $i, !3 = $v, !4 = $k, !5 = $data, !6 = $bl, !7 = $br
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        TYPE_CHECK                                  256  ~8      !0
          2        ASSIGN                                           ~9      !1, ~8
          3        BOOL_NOT                                         ~10     ~9
          4      > JMPZ_EX                                          ~10     ~10, ->8
          5    >   TYPE_CHECK                                  128  ~11     !0
          6        BOOL_NOT                                         ~12     ~11
          7        BOOL                                             ~10     ~12
          8    > > JMPZ                                                     ~10, ->13
    7     9    >   INIT_FCALL_BY_NAME                                       '_js_enc_value'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $13     
         12      > RETURN                                                   $13
    9    13    >   ASSIGN                                                   !2, 0
   10    14        CAST                                          7  ~15     !0
         15        ASSIGN                                                   !0, ~15
   11    16        BOOL_NOT                                         ~17     !1
         17      > JMPZ                                                     ~17, ->28
   12    18    > > FE_RESET_R                                       $18     !0, ->27
         19    > > FE_FETCH_R                                       ~19     $18, !3, ->27
         20    >   ASSIGN                                                   !4, ~19
   13    21        IS_NOT_IDENTICAL                                         !4, !2
         22      > JMPZ                                                     ~21, ->25
   14    23    >   ASSIGN                                                   !1, <true>
   15    24      > JMP                                                      ->27
   17    25    >   PRE_INC                                                  !2
   12    26      > JMP                                                      ->19
         27    >   FE_FREE                                                  $18
   20    28    >   ASSIGN                                                   !5, <array>
   21    29      > FE_RESET_R                                       $25     !0, ->49
         30    > > FE_FETCH_R                                       ~26     $25, !3, ->49
         31    >   ASSIGN                                                   !4, ~26
   22    32        INIT_FCALL_BY_NAME                                       '_js_enc_value'
         33        SEND_VAR_EX                                              !3
         34        DO_FCALL                                      0  $28     
         35        ASSIGN                                                   !3, $28
   23    36      > JMPZ                                                     !1, ->46
   24    37    >   INIT_FCALL_BY_NAME                                       '_js_enc_value'
         38        SEND_VAR_EX                                              !4
         39        DO_FCALL                                      0  $30     
         40        ASSIGN                                                   !4, $30
   25    41        CONCAT                                           ~33     !4, '%3A'
         42        CONCAT                                           ~34     ~33, !3
         43        ASSIGN_DIM                                               !5
         44        OP_DATA                                                  ~34
         45      > JMP                                                      ->48
   27    46    >   ASSIGN_DIM                                               !5
         47        OP_DATA                                                  !3
   21    48    > > JMP                                                      ->30
         49    >   FE_FREE                                                  $25
   30    50      > JMPZ                                                     !1, ->54
   31    51    >   ASSIGN                                                   !6, '%7B'
   32    52        ASSIGN                                                   !7, '%7D'
         53      > JMP                                                      ->56
   34    54    >   ASSIGN                                                   !6, '%5B'
   35    55        ASSIGN                                                   !7, '%5D'
   37    56    >   INIT_FCALL                                               'implode'
         57        SEND_VAL                                                 '%2C'
         58        SEND_VAR                                                 !5
         59        DO_ICALL                                         $40     
         60        CONCAT                                           ~41     !6, $40
         61        CONCAT                                           ~42     ~41, !7
         62      > RETURN                                                   ~42
   38    63*     > RETURN                                                   null

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

Function %00_js_enc_value%2Fin%2FtDdPO%3A40%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/tDdPO
function name:  _js_enc_value
number of ops:  34
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   42     1        TYPE_CHECK                                  128          !0
          2      > JMPNZ                                                    ~2, ->18
   43     3    >   TYPE_CHECK                                  256          !0
          4      > JMPNZ                                                    ~3, ->18
   45     5    >   TYPE_CHECK                                   12          !0
          6      > JMPNZ                                                    ~4, ->22
   47     7    >   TYPE_CHECK                                    2          !0
          8      > JMPNZ                                                    ~5, ->27
   48     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
   50    15    >   TYPE_CHECK                                   64          !0
         16      > JMPNZ                                                    ~8, ->28
         17    > > JMP                                                      ->32
   44    18    >   INIT_FCALL                                               'json_encode'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $9      
         21      > RETURN                                                   $9
   46    22    > > JMPZ                                                     !0, ->25
         23    >   QM_ASSIGN                                        ~10     'true'
         24      > JMP                                                      ->26
         25    >   QM_ASSIGN                                        ~10     'false'
         26    > > RETURN                                                   ~10
   49    27    > > RETURN                                                   'null'
   51    28    >   INIT_FCALL_BY_NAME                                       '_js_uc_esc'
         29        SEND_VAR_EX                                              !0
         30        DO_FCALL                                      0  $11     
         31      > RETURN                                                   $11
   53    32    > > RETURN                                                   !0
   55    33*     > RETURN                                                   null

End of function %00_js_enc_value%2Fin%2FtDdPO%3A40%241

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

End of function %00_js_error%2Fin%2FtDdPO%3A57%242

Function %00_js_uc_esc%2Fin%2FtDdPO%3A64%243:
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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tDdPO
function name:  _js_uc_esc
number of ops:  21
compiled vars:  !0 = $value, !1 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
   65     1        BEGIN_SILENCE                                    ~2      
          2        INIT_FCALL                                               'mb_convert_encoding'
          3        SEND_VAL                                                 'UTF-8'
          4        SEND_VAL                                                 'UTF-8'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        END_SILENCE                                              ~2
          8        IS_NOT_IDENTICAL                                         !0, $3
          9      > JMPZ                                                     ~4, ->11
   66    10    > > RETURN                                                   'null'
   68    11    >   ASSIGN                                                   !1, '%40%5B%08-x010%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'
   69    12        INIT_FCALL                                               'preg_replace_callback'
         13        SEND_VAR                                                 !1
         14        SEND_VAL                                                 '_js_uc_esc_cb'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $6      
         17        CONCAT                                           ~7      '%22', $6
         18        CONCAT                                           ~8      ~7, '%22'
         19      > RETURN                                                   ~8
   70    20*     > RETURN                                                   null

End of function %00_js_uc_esc%2Fin%2FtDdPO%3A64%243

Function %00_js_uc_esc_cb%2Fin%2FtDdPO%3A72%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/tDdPO
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
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
   74     1        ISSET_ISEMPTY_DIM_OBJ                         0          !0, 1
          2      > JMPNZ                                                    ~6, ->4
          3    > > JMP                                                      ->35
   75     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
   76    11        ASSIGN                                                   !2, ''
   77    12        STRLEN                                           ~11     !1
         13        ASSIGN                                                   !3, ~11
   78    14        ASSIGN                                                   !4, 0
         15      > JMP                                                      ->32
   79    16    >   INIT_FCALL                                               'sprintf'
         17        SEND_VAL                                                 '%5Cu%2502x%2502x'
   80    18        INIT_FCALL                                               'ord'
         19        FETCH_DIM_R                                      ~14     !1, !4
         20        SEND_VAL                                                 ~14
         21        DO_ICALL                                         $15     
         22        SEND_VAR                                                 $15
   81    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
   78    31        ASSIGN_OP                                     1          !4, 2
         32    >   IS_SMALLER                                               !4, !3
         33      > JMPNZ                                                    ~22, ->16
   84    34    > > RETURN                                                   !2
   86    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
   88    41*     > RETURN                                                   null

End of function %00_js_uc_esc_cb%2Fin%2FtDdPO%3A72%244

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.55 ms | 1408 KiB | 35 Q