3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set('display_errors', 'On'); error_reporting(E_ALL); try { echo 'JSON decode of null: ' . json_decode(null) . PHP_EOL; if (json_last_error() !== JSON_ERROR_NONE) { echo 'Last JSON error: ' . safe_json_last_error_msg() . PHP_EOL; } } catch (Throwable $t) { echo 'Error from JSON decode of null: ' . $t->getMessage() . PHP_EOL; } try { echo 'JSON decode of empty string: ' . json_decode('') . PHP_EOL; if (json_last_error() !== JSON_ERROR_NONE) { echo 'Last JSON error: ' . safe_json_last_error_msg() . PHP_EOL; } } catch (Throwable $t) { echo 'Error from JSON decode of empty string: ' . $t->getMessage() . PHP_EOL; } function safe_json_last_error_msg() { if (function_exists('json_last_error_msg')) { return json_last_error_msg(); } switch (json_last_error()) { case JSON_ERROR_NONE: return 'No error'; case JSON_ERROR_DEPTH: return 'Maximum stack depth exceeded'; case JSON_ERROR_STATE_MISMATCH: return 'State mismatch (invalid or malformed JSON)'; case JSON_ERROR_CTRL_CHAR: return 'Control character error, possibly incorrectly encoded'; case JSON_ERROR_SYNTAX: return 'Syntax error'; case JSON_ERROR_UTF8: return 'Malformed UTF-8 characters, possibly incorrectly encoded'; default: return 'Unknown error'; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 44
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 22
Found catch point at position: 23
Branch analysis from position: 23
2 jumps found. (Code = 107) Position 1 = 24, Position 2 = -2
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 44
Branch analysis from position: 39
Branch analysis from position: 44
Found catch point at position: 45
Branch analysis from position: 45
2 jumps found. (Code = 107) Position 1 = 46, Position 2 = -2
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aqapV
function name:  (null)
number of ops:  52
compiled vars:  !0 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'ini_set'
          1        SEND_VAL                                                 'display_errors'
          2        SEND_VAL                                                 'On'
          3        DO_ICALL                                                 
    4     4        INIT_FCALL                                               'error_reporting'
          5        SEND_VAL                                                 32767
          6        DO_ICALL                                                 
    7     7        INIT_FCALL                                               'json_decode'
          8        SEND_VAL                                                 null
          9        DO_ICALL                                         $3      
         10        CONCAT                                           ~4      'JSON+decode+of+null%3A+', $3
         11        CONCAT                                           ~5      ~4, '%0A'
         12        ECHO                                                     ~5
    9    13        INIT_FCALL                                               'json_last_error'
         14        DO_ICALL                                         $6      
         15        IS_NOT_IDENTICAL                                         $6, 0
         16      > JMPZ                                                     ~7, ->22
   10    17    >   INIT_FCALL_BY_NAME                                       'safe_json_last_error_msg'
         18        DO_FCALL                                      0  $8      
         19        CONCAT                                           ~9      'Last+JSON+error%3A+', $8
         20        CONCAT                                           ~10     ~9, '%0A'
         21        ECHO                                                     ~10
         22    > > JMP                                                      ->29
   12    23  E > > CATCH                                       last         'Throwable'
   13    24    >   INIT_METHOD_CALL                                         !0, 'getMessage'
         25        DO_FCALL                                      0  $11     
         26        CONCAT                                           ~12     'Error+from+JSON+decode+of+null%3A+', $11
         27        CONCAT                                           ~13     ~12, '%0A'
         28        ECHO                                                     ~13
   17    29    >   INIT_FCALL                                               'json_decode'
         30        SEND_VAL                                                 ''
         31        DO_ICALL                                         $14     
         32        CONCAT                                           ~15     'JSON+decode+of+empty+string%3A+', $14
         33        CONCAT                                           ~16     ~15, '%0A'
         34        ECHO                                                     ~16
   19    35        INIT_FCALL                                               'json_last_error'
         36        DO_ICALL                                         $17     
         37        IS_NOT_IDENTICAL                                         $17, 0
         38      > JMPZ                                                     ~18, ->44
   20    39    >   INIT_FCALL_BY_NAME                                       'safe_json_last_error_msg'
         40        DO_FCALL                                      0  $19     
         41        CONCAT                                           ~20     'Last+JSON+error%3A+', $19
         42        CONCAT                                           ~21     ~20, '%0A'
         43        ECHO                                                     ~21
         44    > > JMP                                                      ->51
   22    45  E > > CATCH                                       last         'Throwable'
   23    46    >   INIT_METHOD_CALL                                         !0, 'getMessage'
         47        DO_FCALL                                      0  $22     
         48        CONCAT                                           ~23     'Error+from+JSON+decode+of+empty+string%3A+', $22
         49        CONCAT                                           ~24     ~23, '%0A'
         50        ECHO                                                     ~24
   41    51    > > RETURN                                                   1

Function safe_json_last_error_msg:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
8 jumps found. (Code = 187) Position 1 = 23, Position 2 = 25, Position 3 = 27, Position 4 = 29, Position 5 = 31, Position 6 = 33, Position 7 = 35, Position 8 = 10
Branch analysis from position: 23
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: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 25
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 27
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 29
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 31
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 33
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 33
Branch analysis from position: 31
Branch analysis from position: 29
Branch analysis from position: 27
Branch analysis from position: 25
Branch analysis from position: 23
filename:       /in/aqapV
function name:  safe_json_last_error_msg
number of ops:  39
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'function_exists'
          1        SEND_VAL                                                 'json_last_error_msg'
          2        DO_ICALL                                         $0      
          3      > JMPZ                                                     $0, ->7
   29     4    >   INIT_FCALL                                               'json_last_error_msg'
          5        DO_ICALL                                         $1      
          6      > RETURN                                                   $1
   32     7    >   INIT_FCALL                                               'json_last_error'
          8        DO_ICALL                                         $2      
          9      > SWITCH_LONG                                              $2, [ 0:->23, 1:->25, 2:->27, 3:->29, 4:->31, 5:->33, ], ->35
         10    >   CASE                                                     $2, 0
         11      > JMPNZ                                                    ~3, ->23
         12    >   CASE                                                     $2, 1
         13      > JMPNZ                                                    ~3, ->25
         14    >   CASE                                                     $2, 2
         15      > JMPNZ                                                    ~3, ->27
         16    >   CASE                                                     $2, 3
         17      > JMPNZ                                                    ~3, ->29
         18    >   CASE                                                     $2, 4
         19      > JMPNZ                                                    ~3, ->31
         20    >   CASE                                                     $2, 5
         21      > JMPNZ                                                    ~3, ->33
         22    > > JMP                                                      ->35
   33    23    >   FREE                                                     $2
         24      > RETURN                                                   'No+error'
   34    25    >   FREE                                                     $2
         26      > RETURN                                                   'Maximum+stack+depth+exceeded'
   35    27    >   FREE                                                     $2
         28      > RETURN                                                   'State+mismatch+%28invalid+or+malformed+JSON%29'
   36    29    >   FREE                                                     $2
         30      > RETURN                                                   'Control+character+error%2C+possibly+incorrectly+encoded'
   37    31    >   FREE                                                     $2
         32      > RETURN                                                   'Syntax+error'
   38    33    >   FREE                                                     $2
         34      > RETURN                                                   'Malformed+UTF-8+characters%2C+possibly+incorrectly+encoded'
   39    35    >   FREE                                                     $2
         36      > RETURN                                                   'Unknown+error'
         37*       FREE                                                     $2
   41    38*     > RETURN                                                   null

End of function safe_json_last_error_msg

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.61 ms | 1012 KiB | 19 Q