3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isJson($string, $assoc = false) { var_dump(json_decode($string)); if(is_string($string)) { json_decode($string, $assoc); return (json_last_error() == JSON_ERROR_NONE); // return json_decode($str) != null; } return false; } $a=['arraiii'=>['dentro'=>234]]; $b=json_encode($a); $c='{ "book": [ { "id":"01", "language": "Java", "edition": "third", "author": "Herbert Schildt" }, { "id":"07", "language": "C++", "edition": "second" "author": "E.Balagurusamy" }] }'; var_dump(isJson($c));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Oa0RU
function name:  (null)
number of ops:  13
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                   !0, <array>
   21     1        INIT_FCALL                                               'json_encode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
   22     5        ASSIGN                                                   !2, '%7B%0A++++%22book%22%3A+%5B%0A++++%7B%0A+++++++%22id%22%3A%2201%22%2C%0A+++++++%22language%22%3A+%22Java%22%2C%0A+++++++%22edition%22%3A+%22third%22%2C%0A+++++++%22author%22%3A+%22Herbert+Schildt%22%0A++++%7D%2C%0A++++%7B%0A+++++++%22id%22%3A%2207%22%2C%0A+++++++%22language%22%3A+%22C%2B%2B%22%2C%0A+++++++%22edition%22%3A+%22second%22%0A+++++++%22author%22%3A+%22E.Balagurusamy%22%0A++++%7D%5D%0A%7D'
   38     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'isjson'
          8        SEND_VAR                                                 !2
          9        DO_FCALL                                      0  $7      
         10        SEND_VAR                                                 $7
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function isjson:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Oa0RU
function name:  isJson
number of ops:  20
compiled vars:  !0 = $string, !1 = $assoc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
    8     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'json_decode'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
   10     8        TYPE_CHECK                                   64          !0
          9      > JMPZ                                                     ~4, ->18
   11    10    >   INIT_FCALL                                               'json_decode'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
   12    14        INIT_FCALL                                               'json_last_error'
         15        DO_ICALL                                         $6      
         16        IS_EQUAL                                         ~7      $6, 0
         17      > RETURN                                                   ~7
   15    18    > > RETURN                                                   <false>
   16    19*     > RETURN                                                   null

End of function isjson

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.51 ms | 1390 KiB | 22 Q