3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function test($array) { try { return is_indexed_array($array); } catch (Exception $e) { echo $e->getMessage(); return 'error'; } } // non-array - adjust according to your preferred error handling technique assert(test(null) === false); assert(test(false) === false); assert(test(new stdClass) === false); // empty array assert(test([]) === true); // numeric keys assert(test([null, 'a', 'b']) === true); // proper indexed array; also, to catch wrong isset usage assert(test([1 => 'a', 2 => 'b', 3 => 'c']) === false); // sequential but not 0-based assert(test([-1 => '', 0 => '', 1 => 'a']) === false); // sequential but not 0-based assert(test([0 => '', 2 => 'b', 3 => 'c']) === false); // 1 index missing assert(test([0 => '', 2 => 'b', 1 => 'a']) === false); // numeric but unordered assert(test([0 => '']) === true); // single item assert(test([1 => 'a']) === false); // single item assert(test([NAN]) === true); assert(test([NAN => '']) === false); assert(test([INF]) === true); assert(test([INF => '']) === false); // string keys assert(test(['' => '', 'a' => 'a', 'b' => 'b']) === false); // proper associative array assert(test(['' => '']) === false); // single item; also, associative even though '' == 0 // mixed keys assert(test(['' => '', 1 => 'a']) === false); // first key string but rest not assert(test(['' => '', 0 => '']) === false); // first key string but rest not assert(test([0 => '', 'a' => 'a']) === false); // first key numeric but rest not // numeric string keys assert(test([' 0' => '']) === false); // associative even though ' 0' == 0 assert(test(['00' => '']) === false); // associative even though '00' == 0 assert(test(['0*' => '']) === false); // associative even though '0*' == 0 assert(test(['0.0' => '']) === false); // associative even though '0.0' == 0.0 assert(test(['0x0' => '']) === false); // associative even though '0x0' == 0 assert(test(['0e0' => '']) === false); // associative even though '0e0' == 0 $obj = new stdClass; $obj->{0} = ''; assert(test((array)$obj) === false); // to catch ['0' => ''] like situations function is_indexed_array(&$array) { if (!is_array($array)) return false; $i = -1; foreach ($array as $k => $v) if ($k !== ++$i) return false; return $i === -1; }
based on HUdsf
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/iZIm9
function name:  (null)
number of ops:  254
compiled vars:  !0 = $obj
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   NOP                                                      
  21     1        ASSERT_CHECK                                             
         2        INIT_FCALL                                               'assert'
         3        INIT_FCALL                                               'test'
         4        SEND_VAL                                                 null
         5        DO_FCALL                                      0  $1      
         6        IS_IDENTICAL                                     ~2      $1, <false>
         7        SEND_VAL                                                 ~2
         8        SEND_VAL                                                 'assert%28test%28null%29+%3D%3D%3D+false%29'
         9        DO_ICALL                                                 
  22    10        ASSERT_CHECK                                             
        11        INIT_FCALL                                               'assert'
        12        INIT_FCALL                                               'test'
        13        SEND_VAL                                                 <false>
        14        DO_FCALL                                      0  $4      
        15        IS_IDENTICAL                                     ~5      $4, <false>
        16        SEND_VAL                                                 ~5
        17        SEND_VAL                                                 'assert%28test%28false%29+%3D%3D%3D+false%29'
        18        DO_ICALL                                                 
  23    19        ASSERT_CHECK                                             
        20        INIT_FCALL                                               'assert'
        21        INIT_FCALL                                               'test'
        22        NEW                                              $7      :6
        23        DO_FCALL                                      0          
        24        SEND_VAR                                                 $7
        25        DO_FCALL                                      0  $9      
        26        IS_IDENTICAL                                     ~10     $9, <false>
        27        SEND_VAL                                                 ~10
        28        SEND_VAL                                                 'assert%28test%28new+stdClass%28%29%29+%3D%3D%3D+false%29'
        29        DO_ICALL                                                 
  26    30        ASSERT_CHECK                                             
        31        INIT_FCALL                                               'assert'
        32        INIT_FCALL                                               'test'
        33        SEND_VAL                                                 <array>
        34        DO_FCALL                                      0  $12     
        35        IS_IDENTICAL                                     ~13     $12, <true>
        36        SEND_VAL                                                 ~13
        37        SEND_VAL                                                 'assert%28test%28%5B%5D%29+%3D%3D%3D+true%29'
        38        DO_ICALL                                                 
  29    39        ASSERT_CHECK                                             
        40        INIT_FCALL                                               'assert'
        41        INIT_FCALL                                               'test'
        42        SEND_VAL                                                 <array>
        43        DO_FCALL                                      0  $15     
        44        IS_IDENTICAL                                     ~16     $15, <true>
        45        SEND_VAL                                                 ~16
        46        SEND_VAL                                                 'assert%28test%28%5Bnull%2C+%27a%27%2C+%27b%27%5D%29+%3D%3D%3D+true%29'
        47        DO_ICALL                                                 
  30    48        ASSERT_CHECK                                             
        49        INIT_FCALL                                               'assert'
        50        INIT_FCALL                                               'test'
        51        SEND_VAL                                                 <array>
        52        DO_FCALL                                      0  $18     
        53        IS_IDENTICAL                                     ~19     $18, <false>
        54        SEND_VAL                                                 ~19
        55        SEND_VAL                                                 'assert%28test%28%5B1+%3D%3E+%27a%27%2C+2+%3D%3E+%27b%27%2C+3+%3D%3E+%27c%27%5D%29+%3D%3D%3D+false%29'
        56        DO_ICALL                                                 
  31    57        ASSERT_CHECK                                             
        58        INIT_FCALL                                               'assert'
        59        INIT_FCALL                                               'test'
        60        SEND_VAL                                                 <array>
        61        DO_FCALL                                      0  $21     
        62        IS_IDENTICAL                                     ~22     $21, <false>
        63        SEND_VAL                                                 ~22
        64        SEND_VAL                                                 'assert%28test%28%5B-1+%3D%3E+%27%27%2C+0+%3D%3E+%27%27%2C+1+%3D%3E+%27a%27%5D%29+%3D%3D%3D+false%29'
        65        DO_ICALL                                                 
  32    66        ASSERT_CHECK                                             
        67        INIT_FCALL                                               'assert'
        68        INIT_FCALL                                               'test'
        69        SEND_VAL                                                 <array>
        70        DO_FCALL                                      0  $24     
        71        IS_IDENTICAL                                     ~25     $24, <false>
        72        SEND_VAL                                                 ~25
        73        SEND_VAL                                                 'assert%28test%28%5B0+%3D%3E+%27%27%2C+2+%3D%3E+%27b%27%2C+3+%3D%3E+%27c%27%5D%29+%3D%3D%3D+false%29'
        74        DO_ICALL                                                 
  33    75        ASSERT_CHECK                                             
        76        INIT_FCALL                                               'assert'
        77        INIT_FCALL                                               'test'
        78        SEND_VAL                                                 <array>
        79        DO_FCALL                                      0  $27     
        80        IS_IDENTICAL                                     ~28     $27, <false>
        81        SEND_VAL                                                 ~28
        82        SEND_VAL                                                 'assert%28test%28%5B0+%3D%3E+%27%27%2C+2+%3D%3E+%27b%27%2C+1+%3D%3E+%27a%27%5D%29+%3D%3D%3D+false%29'
        83        DO_ICALL                                                 
  34    84        ASSERT_CHECK                                             
        85        INIT_FCALL                                               'assert'
        86        INIT_FCALL                                               'test'
        87        SEND_VAL                                                 <array>
        88        DO_FCALL                                      0  $30     
        89        IS_IDENTICAL                                     ~31     $30, <true>
        90        SEND_VAL                                                 ~31
        91        SEND_VAL                                                 'assert%28test%28%5B0+%3D%3E+%27%27%5D%29+%3D%3D%3D+true%29'
        92        DO_ICALL                                                 
  35    93        ASSERT_CHECK                                             
        94        INIT_FCALL                                               'assert'
        95        INIT_FCALL                                               'test'
        96        SEND_VAL                                                 <array>
        97        DO_FCALL                                      0  $33     
        98        IS_IDENTICAL                                     ~34     $33, <false>
        99        SEND_VAL                                                 ~34
       100        SEND_VAL                                                 'assert%28test%28%5B1+%3D%3E+%27a%27%5D%29+%3D%3D%3D+false%29'
       101        DO_ICALL                                                 
  36   102        ASSERT_CHECK                                             
       103        INIT_FCALL                                               'assert'
       104        INIT_FCALL                                               'test'
       105        SEND_VAL                                                 <array>
       106        DO_FCALL                                      0  $36     
       107        IS_IDENTICAL                                     ~37     $36, <true>
       108        SEND_VAL                                                 ~37
       109        SEND_VAL                                                 'assert%28test%28%5BNAN%5D%29+%3D%3D%3D+true%29'
       110        DO_ICALL                                                 
  37   111        ASSERT_CHECK                                             
       112        INIT_FCALL                                               'assert'
       113        INIT_FCALL                                               'test'
       114        SEND_VAL                                                 <array>
       115        DO_FCALL                                      0  $39     
       116        IS_IDENTICAL                                     ~40     $39, <false>
       117        SEND_VAL                                                 ~40
       118        SEND_VAL                                                 'assert%28test%28%5BNAN+%3D%3E+%27%27%5D%29+%3D%3D%3D+false%29'
       119        DO_ICALL                                                 
  38   120        ASSERT_CHECK                                             
       121        INIT_FCALL                                               'assert'
       122        INIT_FCALL                                               'test'
       123        SEND_VAL                                                 <array>
       124        DO_FCALL                                      0  $42     
       125        IS_IDENTICAL                                     ~43     $42, <true>
       126        SEND_VAL                                                 ~43
       127        SEND_VAL                                                 'assert%28test%28%5BINF%5D%29+%3D%3D%3D+true%29'
       128        DO_ICALL                                                 
  39   129        ASSERT_CHECK                                             
       130        INIT_FCALL                                               'assert'
       131        INIT_FCALL                                               'test'
       132        SEND_VAL                                                 <array>
       133        DO_FCALL                                      0  $45     
       134        IS_IDENTICAL                                     ~46     $45, <false>
       135        SEND_VAL                                                 ~46
       136        SEND_VAL                                                 'assert%28test%28%5BINF+%3D%3E+%27%27%5D%29+%3D%3D%3D+false%29'
       137        DO_ICALL                                                 
  42   138        ASSERT_CHECK                                             
       139        INIT_FCALL                                               'assert'
       140        INIT_FCALL                                               'test'
       141        SEND_VAL                                                 <array>
       142        DO_FCALL                                      0  $48     
       143        IS_IDENTICAL                                     ~49     $48, <false>
       144        SEND_VAL                                                 ~49
       145        SEND_VAL                                                 'assert%28test%28%5B%27%27+%3D%3E+%27%27%2C+%27a%27+%3D%3E+%27a%27%2C+%27b%27+%3D%3E+%27b%27%5D%29+%3D%3D%3D+false%29'
       146        DO_ICALL                                                 
  43   147        ASSERT_CHECK                                             
       148        INIT_FCALL                                               'assert'
       149        INIT_FCALL                                               'test'
       150        SEND_VAL                                                 <array>
       151        DO_FCALL                                      0  $51     
       152        IS_IDENTICAL                                     ~52     $51, <false>
       153        SEND_VAL                                                 ~52
       154        SEND_VAL                                                 'assert%28test%28%5B%27%27+%3D%3E+%27%27%5D%29+%3D%3D%3D+false%29'
       155        DO_ICALL                                                 
  46   156        ASSERT_CHECK                                             
       157        INIT_FCALL                                               'assert'
       158        INIT_FCALL                                               'test'
       159        SEND_VAL                                                 <array>
       160        DO_FCALL                                      0  $54     
       161        IS_IDENTICAL                                     ~55     $54, <false>
       162        SEND_VAL                                                 ~55
       163        SEND_VAL                                                 'assert%28test%28%5B%27%27+%3D%3E+%27%27%2C+1+%3D%3E+%27a%27%5D%29+%3D%3D%3D+false%29'
       164        DO_ICALL                                                 
  47   165        ASSERT_CHECK                                             
       166        INIT_FCALL                                               'assert'
       167        INIT_FCALL                                               'test'
       168        SEND_VAL                                                 <array>
       169        DO_FCALL                                      0  $57     
       170        IS_IDENTICAL                                     ~58     $57, <false>
       171        SEND_VAL                                                 ~58
       172        SEND_VAL                                                 'assert%28test%28%5B%27%27+%3D%3E+%27%27%2C+0+%3D%3E+%27%27%5D%29+%3D%3D%3D+false%29'
       173        DO_ICALL                                                 
  48   174        ASSERT_CHECK                                             
       175        INIT_FCALL                                               'assert'
       176        INIT_FCALL                                               'test'
       177        SEND_VAL                                                 <array>
       178        DO_FCALL                                      0  $60     
       179        IS_IDENTICAL                                     ~61     $60, <false>
       180        SEND_VAL                                                 ~61
       181        SEND_VAL                                                 'assert%28test%28%5B0+%3D%3E+%27%27%2C+%27a%27+%3D%3E+%27a%27%5D%29+%3D%3D%3D+false%29'
       182        DO_ICALL                                                 
  51   183        ASSERT_CHECK                                             
       184        INIT_FCALL                                               'assert'
       185        INIT_FCALL                                               'test'
       186        SEND_VAL                                                 <array>
       187        DO_FCALL                                      0  $63     
       188        IS_IDENTICAL                                     ~64     $63, <false>
       189        SEND_VAL                                                 ~64
       190        SEND_VAL                                                 'assert%28test%28%5B%27+0%27+%3D%3E+%27%27%5D%29+%3D%3D%3D+false%29'
       191        DO_ICALL                                                 
  52   192        ASSERT_CHECK                                             
       193        INIT_FCALL                                               'assert'
       194        INIT_FCALL                                               'test'
       195        SEND_VAL                                                 <array>
       196        DO_FCALL                                      0  $66     
       197        IS_IDENTICAL                                     ~67     $66, <false>
       198        SEND_VAL                                                 ~67
       199        SEND_VAL                                                 'assert%28test%28%5B%2700%27+%3D%3E+%27%27%5D%29+%3D%3D%3D+false%29'
       200        DO_ICALL                                                 
  53   201        ASSERT_CHECK                                             
       202        INIT_FCALL                                               'assert'
       203        INIT_FCALL                                               'test'
       204        SEND_VAL                                                 <array>
       205        DO_FCALL                                      0  $69     
       206        IS_IDENTICAL                                     ~70     $69, <false>
       207        SEND_VAL                                                 ~70
       208        SEND_VAL                                                 'assert%28test%28%5B%270%2A%27+%3D%3E+%27%27%5D%29+%3D%3D%3D+false%29'
       209        DO_ICALL                                                 
  54   210        ASSERT_CHECK                                             
       211        INIT_FCALL                                               'assert'
       212        INIT_FCALL                                               'test'
       213        SEND_VAL                                                 <array>
       214        DO_FCALL                                      0  $72     
       215        IS_IDENTICAL                                     ~73     $72, <false>
       216        SEND_VAL                                                 ~73
       217        SEND_VAL                                                 'assert%28test%28%5B%270.0%27+%3D%3E+%27%27%5D%29+%3D%3D%3D+false%29'
       218        DO_ICALL                                                 
  55   219        ASSERT_CHECK                                             
       220        INIT_FCALL                                               'assert'
       221        INIT_FCALL                                               'test'
       222        SEND_VAL                                                 <array>
       223        DO_FCALL                                      0  $75     
       224        IS_IDENTICAL                                     ~76     $75, <false>
       225        SEND_VAL                                                 ~76
       226        SEND_VAL                                                 'assert%28test%28%5B%270x0%27+%3D%3E+%27%27%5D%29+%3D%3D%3D+false%29'
       227        DO_ICALL                                                 
  56   228        ASSERT_CHECK                                             
       229        INIT_FCALL                                               'assert'
       230        INIT_FCALL                                               'test'
       231        SEND_VAL                                                 <array>
       232        DO_FCALL                                      0  $78     
       233        IS_IDENTICAL                                     ~79     $78, <false>
       234        SEND_VAL                                                 ~79
       235        SEND_VAL                                                 'assert%28test%28%5B%270e0%27+%3D%3E+%27%27%5D%29+%3D%3D%3D+false%29'
       236        DO_ICALL                                                 
  57   237        NEW                                              $81     :125
       238        DO_FCALL                                      0          
       239        ASSIGN                                                   !0, $81
       240        ASSIGN_OBJ                                               !0, '0'
       241        OP_DATA                                                  ''
  58   242        ASSERT_CHECK                                             
       243        INIT_FCALL                                               'assert'
       244        INIT_FCALL                                               'test'
       245        CAST                                          7  ~85     !0
       246        SEND_VAL                                                 ~85
       247        DO_FCALL                                      0  $86     
       248        IS_IDENTICAL                                     ~87     $86, <false>
       249        SEND_VAL                                                 ~87
       250        SEND_VAL                                                 'assert%28test%28%28array%29%24obj%29+%3D%3D%3D+false%29'
       251        DO_ICALL                                                 
  62   252        NOP                                                      
  73   253      > RETURN                                                   1

Function test:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
Found catch point at position: 6
Branch analysis from position: 6
Jump found. Position 1 = 7, Position 2 = -2
Branch analysis from position: 7
Jump found. Position 1 = -2
filename:       /in/iZIm9
function name:  test
number of ops:  12
compiled vars:  !0 = $array, !1 = $e
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   RECV                                             !0      
   7     1        INIT_FCALL_BY_NAME                                       'is_indexed_array'
         2        SEND_VAR_EX                                              !0
         3        DO_FCALL                                      0  $2      
         4      > RETURN                                                   $2
         5*       JMP                                                      ->11
   9     6  E > > CATCH                                                    'Exception', !1
  11     7    >   INIT_METHOD_CALL                                         !1, 'getMessage'
         8        DO_FCALL                                      0  $3      
         9        ECHO                                                     $3
  12    10      > RETURN                                                   'error'
  14    11*     > RETURN                                                   null

End of function test

Function is_indexed_array:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
Jump found. Position 1 = -2
Branch analysis from position: 5
Jump found. Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
Jump found. Position 1 = 8, Position 2 = 15
Branch analysis from position: 8
Jump found. Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
Jump found. Position 1 = -2
Branch analysis from position: 14
Jump found. Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 15
Jump found. Position 1 = -2
Branch analysis from position: 15
filename:       /in/iZIm9
function name:  is_indexed_array
number of ops:  19
compiled vars:  !0 = $array, !1 = $i, !2 = $v, !3 = $k
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  62     0  E >   RECV                                             !0      
  64     1        TYPE_CHECK                                    7  ~4      !0
         2        BOOL_NOT                                         ~5      ~4
         3      > JMPZ                                                     ~5, ->5
  65     4    > > RETURN                                                   <false>
  67     5    >   ASSIGN                                                   !1, -1
  68     6      > FE_RESET_R                                       $7      !0, ->15
         7    > > FE_FETCH_R                                       ~8      $7, !2, ->15
         8    >   ASSIGN                                                   !3, ~8
  69     9        PRE_INC                                          $10     !1
        10        IS_NOT_IDENTICAL                                 ~11     !3, $10
        11      > JMPZ                                                     ~11, ->14
  70    12    >   FE_FREE                                                  $7
        13      > RETURN                                                   <false>
        14    > > JMP                                                      ->7
        15    >   FE_FREE                                                  $7
  72    16        IS_IDENTICAL                                     ~12     !1, -1
        17      > RETURN                                                   ~12
  73    18*     > RETURN                                                   null

End of function is_indexed_array

Generated using Vulcan Logic Dumper, using php 7.1.0