3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fmt = "%-12s %-20s %-20s %-10s %-5s\n"; function json_cmp($x, $y) { global $fmt; $error = array("-", "FAIL"); printf($fmt, var_export($x, true), str_replace("\n", "", var_export($y, true)), str_replace("\n", "", var_export(json_decode($x), true)), $error[json_last_error() > 0], $error[json_decode($x) !== $y] ); } printf($fmt, "JSON", "Expected", "Actual", "JSON_ERROR", "PASS"); printf("---------------------------------------------------------------------- \n"); // works json_cmp("true", true); // fails - is actually true json_cmp("tRue", NULL); // fails - is actually NULL json_cmp("true ", true); // works json_cmp("[true ] ", array(true)); json_cmp("[ true ] ", array(true)); json_cmp("[true] ", array(true)); // works, even though the non-array version fails json_cmp("[tRue]", NULL); json_cmp("0", 0); json_cmp("1", 1); json_cmp("false", false); json_cmp("'foo'", NULL); json_cmp('"foo"', "foo"); json_cmp('1.123', 1.123); json_cmp('1.123 ', 1.123); json_cmp(' 1.123', 1.123); json_cmp('42', 42); json_cmp('42 ', 42); json_cmp(' 42', 42); json_cmp(".123", 0.123);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nTHph
function name:  (null)
number of ops:  89
compiled vars:  !0 = $fmt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%25-12s+%25-20s+%25-20s+%25-10s+%25-5s%0A'
   17     1        INIT_FCALL                                               'printf'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'JSON'
          4        SEND_VAL                                                 'Expected'
          5        SEND_VAL                                                 'Actual'
          6        SEND_VAL                                                 'JSON_ERROR'
          7        SEND_VAL                                                 'PASS'
          8        DO_ICALL                                                 
   18     9        INIT_FCALL                                               'printf'
         10        SEND_VAL                                                 '----------------------------------------------------------------------%0A%0A'
         11        DO_ICALL                                                 
   22    12        INIT_FCALL                                               'json_cmp'
         13        SEND_VAL                                                 'true'
         14        SEND_VAL                                                 <true>
         15        DO_FCALL                                      0          
   25    16        INIT_FCALL                                               'json_cmp'
         17        SEND_VAL                                                 'tRue'
         18        SEND_VAL                                                 null
         19        DO_FCALL                                      0          
   28    20        INIT_FCALL                                               'json_cmp'
         21        SEND_VAL                                                 'true+'
         22        SEND_VAL                                                 <true>
         23        DO_FCALL                                      0          
   31    24        INIT_FCALL                                               'json_cmp'
         25        SEND_VAL                                                 '%5Btrue+%5D+'
         26        SEND_VAL                                                 <array>
         27        DO_FCALL                                      0          
   32    28        INIT_FCALL                                               'json_cmp'
         29        SEND_VAL                                                 '%5B+true+%5D+'
         30        SEND_VAL                                                 <array>
         31        DO_FCALL                                      0          
   33    32        INIT_FCALL                                               'json_cmp'
         33        SEND_VAL                                                 '%5Btrue%5D+'
         34        SEND_VAL                                                 <array>
         35        DO_FCALL                                      0          
   36    36        INIT_FCALL                                               'json_cmp'
         37        SEND_VAL                                                 '%5BtRue%5D'
         38        SEND_VAL                                                 null
         39        DO_FCALL                                      0          
   38    40        INIT_FCALL                                               'json_cmp'
         41        SEND_VAL                                                 '0'
         42        SEND_VAL                                                 0
         43        DO_FCALL                                      0          
   39    44        INIT_FCALL                                               'json_cmp'
         45        SEND_VAL                                                 '1'
         46        SEND_VAL                                                 1
         47        DO_FCALL                                      0          
   41    48        INIT_FCALL                                               'json_cmp'
         49        SEND_VAL                                                 'false'
         50        SEND_VAL                                                 <false>
         51        DO_FCALL                                      0          
   43    52        INIT_FCALL                                               'json_cmp'
         53        SEND_VAL                                                 '%27foo%27'
         54        SEND_VAL                                                 null
         55        DO_FCALL                                      0          
   45    56        INIT_FCALL                                               'json_cmp'
         57        SEND_VAL                                                 '%22foo%22'
         58        SEND_VAL                                                 'foo'
         59        DO_FCALL                                      0          
   47    60        INIT_FCALL                                               'json_cmp'
         61        SEND_VAL                                                 '1.123'
         62        SEND_VAL                                                 1.123
         63        DO_FCALL                                      0          
   48    64        INIT_FCALL                                               'json_cmp'
         65        SEND_VAL                                                 '1.123+'
         66        SEND_VAL                                                 1.123
         67        DO_FCALL                                      0          
   49    68        INIT_FCALL                                               'json_cmp'
         69        SEND_VAL                                                 '+1.123'
         70        SEND_VAL                                                 1.123
         71        DO_FCALL                                      0          
   51    72        INIT_FCALL                                               'json_cmp'
         73        SEND_VAL                                                 '42'
         74        SEND_VAL                                                 42
         75        DO_FCALL                                      0          
   52    76        INIT_FCALL                                               'json_cmp'
         77        SEND_VAL                                                 '42+'
         78        SEND_VAL                                                 42
         79        DO_FCALL                                      0          
   53    80        INIT_FCALL                                               'json_cmp'
         81        SEND_VAL                                                 '+42'
         82        SEND_VAL                                                 42
         83        DO_FCALL                                      0          
   55    84        INIT_FCALL                                               'json_cmp'
         85        SEND_VAL                                                 '.123'
         86        SEND_VAL                                                 0.123
         87        DO_FCALL                                      0          
         88      > RETURN                                                   1

Function json_cmp:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nTHph
function name:  json_cmp
number of ops:  47
compiled vars:  !0 = $x, !1 = $y, !2 = $fmt, !3 = $error
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        BIND_GLOBAL                                              !2, 'fmt'
    7     3        ASSIGN                                                   !3, <array>
    8     4        INIT_FCALL                                               'printf'
          5        SEND_VAR                                                 !2
    9     6        INIT_FCALL                                               'var_export'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $5      
         10        SEND_VAR                                                 $5
   10    11        INIT_FCALL                                               'str_replace'
         12        SEND_VAL                                                 '%0A'
         13        SEND_VAL                                                 ''
         14        INIT_FCALL                                               'var_export'
         15        SEND_VAR                                                 !1
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $6      
         18        SEND_VAR                                                 $6
         19        DO_ICALL                                         $7      
         20        SEND_VAR                                                 $7
   11    21        INIT_FCALL                                               'str_replace'
         22        SEND_VAL                                                 '%0A'
         23        SEND_VAL                                                 ''
         24        INIT_FCALL                                               'var_export'
         25        INIT_FCALL                                               'json_decode'
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $8      
         28        SEND_VAR                                                 $8
         29        SEND_VAL                                                 <true>
         30        DO_ICALL                                         $9      
         31        SEND_VAR                                                 $9
         32        DO_ICALL                                         $10     
         33        SEND_VAR                                                 $10
   12    34        INIT_FCALL                                               'json_last_error'
         35        DO_ICALL                                         $11     
         36        IS_SMALLER                                       ~12     0, $11
         37        FETCH_DIM_R                                      ~13     !3, ~12
         38        SEND_VAL                                                 ~13
   13    39        INIT_FCALL                                               'json_decode'
         40        SEND_VAR                                                 !0
         41        DO_ICALL                                         $14     
         42        IS_NOT_IDENTICAL                                 ~15     !1, $14
         43        FETCH_DIM_R                                      ~16     !3, ~15
         44        SEND_VAL                                                 ~16
         45        DO_ICALL                                                 
   15    46      > RETURN                                                   null

End of function json_cmp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.94 ms | 1407 KiB | 42 Q