3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Issue 1, empty associative arrays (dictionaries) become regular arrays. $dictionary = array('key' => 'value'); var_dump(json_encode($dictionary)); // gives '{"key":"value"}'; unset($dictionary['key']); var_dump(json_encode($dictionary)); // Gives '[]' -> json dictionary turned into array var_dump(json_encode((Object)$dictionary)); // Gives '{}' -> json dictionary stays dictionary // Issue 2, array manipulations that involve the array indexes, turn numeric arrays into dictionaries. $fruits = array("apples", "oranges"); var_dump(json_encode($fruits)); // Gives ["apples", "oranges"] unset($fruits[0]); // Don't like apples. var_dump(json_encode($fruits)); // Gives '{"1":"oranges"}' -> wow, array turned into dictionary.
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r1W6h
function name:  (null)
number of ops:  36
compiled vars:  !0 = $dictionary, !1 = $fruits
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, <array>
    6     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'json_encode'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        SEND_VAR                                                 $3
          6        DO_ICALL                                                 
    8     7        UNSET_DIM                                                !0, 'key'
   10     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'json_encode'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $5      
         12        SEND_VAR                                                 $5
         13        DO_ICALL                                                 
   12    14        INIT_FCALL                                               'var_dump'
         15        INIT_FCALL                                               'json_encode'
         16        CAST                                          8  ~7      !0
         17        SEND_VAL                                                 ~7
         18        DO_ICALL                                         $8      
         19        SEND_VAR                                                 $8
         20        DO_ICALL                                                 
   16    21        ASSIGN                                                   !1, <array>
   18    22        INIT_FCALL                                               'var_dump'
         23        INIT_FCALL                                               'json_encode'
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                         $11     
         26        SEND_VAR                                                 $11
         27        DO_ICALL                                                 
   20    28        UNSET_DIM                                                !1, 0
   22    29        INIT_FCALL                                               'var_dump'
         30        INIT_FCALL                                               'json_encode'
         31        SEND_VAR                                                 !1
         32        DO_ICALL                                         $13     
         33        SEND_VAR                                                 $13
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.83 ms | 1396 KiB | 17 Q