3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isJson2($string) { try { json_decode($string); } catch (ErrorException $e) { return FALSE; } return (json_last_error() == JSON_ERROR_NONE); } /** * Checks whether a string is valid JSON. * * @param string $string * @return boolean */ function isJson($string) { // Make sure the string is not empty and whether it is a string. if(!empty($string) && is_string($string)) { json_decode($string); return (json_last_error() == JSON_ERROR_NONE); } return false; } $a=['arraiii'=>['dentro'=>234]]; $b=json_encode('asdf'); $c=''; var_dump(json_decode($b)); var_dump(isJson($b));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l36vp
function name:  (null)
number of ops:  19
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ASSIGN                                                   !0, <array>
   36     1        INIT_FCALL                                               'json_encode'
          2        SEND_VAL                                                 'asdf'
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
   37     5        ASSIGN                                                   !2, ''
   39     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'json_decode'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $7      
         10        SEND_VAR                                                 $7
         11        DO_ICALL                                                 
   41    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'isjson'
         14        SEND_VAR                                                 !1
         15        DO_FCALL                                      0  $9      
         16        SEND_VAR                                                 $9
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Function isjson2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 5
Branch analysis from position: 5
2 jumps found. (Code = 107) Position 1 = 6, Position 2 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l36vp
function name:  isJson2
number of ops:  12
compiled vars:  !0 = $string, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
          4      > JMP                                                      ->7
    8     5  E > > CATCH                                       last         'ErrorException'
   10     6    > > RETURN                                                   <false>
   13     7    >   INIT_FCALL                                               'json_last_error'
          8        DO_ICALL                                         $3      
          9        IS_EQUAL                                         ~4      $3, 0
         10      > RETURN                                                   ~4
   14    11*     > RETURN                                                   null

End of function isjson2

Function isjson:
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 = 43) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
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: 6
filename:       /in/l36vp
function name:  isJson
number of ops:  16
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ_EX                                          ~2      ~2, ->6
          4    >   TYPE_CHECK                                   64  ~3      !0
          5        BOOL                                             ~2      ~3
          6    > > JMPZ                                                     ~2, ->14
   26     7    >   INIT_FCALL                                               'json_decode'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                                 
   27    10        INIT_FCALL                                               'json_last_error'
         11        DO_ICALL                                         $5      
         12        IS_EQUAL                                         ~6      $5, 0
         13      > RETURN                                                   ~6
   30    14    > > RETURN                                                   <false>
   31    15*     > RETURN                                                   null

End of function isjson

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.75 ms | 1394 KiB | 22 Q