3v4l.org

run code in 300+ PHP versions simultaneously
<?php mt_srand( 1234 ); // Arrange $input = []; for ($i = 0; $i < 10; $i++ ) { $input[] = wfRandomString( 5 ); } // Act $map = []; foreach ( $input as $str ) { $map[$str] = 'something computed something'; } $output = []; foreach ( $map as $str => $somthing ) { $output[] = $str; } // Assert foreach ( $output as $str ) { if ( !is_string( $str ) ) { echo "WAT: "; var_dump( $str ); } else { echo "OK: "; var_dump( $str ); } } echo json_encode( $output, JSON_PRETTY_PRINT ); // ------- /** From MediaWiki 1.35 - https://w.wiki/oyY */ function wfRandomString( $length ) : string { $str = ''; for ( $n = 0; $n < $length; $n += 7 ) { $str .= sprintf( '%07x', mt_rand() & 0xfffffff ); } return substr( $str, 0, $length ); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 44
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 44
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 39
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 28
Branch analysis from position: 20
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
Branch analysis from position: 6
filename:       /in/odIiW
function name:  (null)
number of ops:  51
compiled vars:  !0 = $input, !1 = $i, !2 = $map, !3 = $str, !4 = $output, !5 = $somthing
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    1     0  E >   INIT_FCALL                                               'mt_srand'
          1        SEND_VAL                                                 1234
          2        DO_ICALL                                                 
    5     3        ASSIGN                                                   !0, <array>
    6     4        ASSIGN                                                   !1, 0
          5      > JMP                                                      ->12
    7     6    >   INIT_FCALL_BY_NAME                                       'wfRandomString'
          7        SEND_VAL_EX                                              5
          8        DO_FCALL                                      0  $10     
          9        ASSIGN_DIM                                               !0
         10        OP_DATA                                                  $10
    6    11        PRE_INC                                                  !1
         12    >   IS_SMALLER                                               !1, 10
         13      > JMPNZ                                                    ~12, ->6
   12    14    >   ASSIGN                                                   !2, <array>
   13    15      > FE_RESET_R                                       $14     !0, ->20
         16    > > FE_FETCH_R                                               $14, !3, ->20
   14    17    >   ASSIGN_DIM                                               !2, !3
         18        OP_DATA                                                  'something+computed+something'
   13    19      > JMP                                                      ->16
         20    >   FE_FREE                                                  $14
   16    21        ASSIGN                                                   !4, <array>
   17    22      > FE_RESET_R                                       $17     !2, ->28
         23    > > FE_FETCH_R                                       ~18     $17, !5, ->28
         24    >   ASSIGN                                                   !3, ~18
   18    25        ASSIGN_DIM                                               !4
         26        OP_DATA                                                  !3
   17    27      > JMP                                                      ->23
         28    >   FE_FREE                                                  $17
   23    29      > FE_RESET_R                                       $21     !4, ->44
         30    > > FE_FETCH_R                                               $21, !3, ->44
   24    31    >   TYPE_CHECK                                   64  ~22     !3
         32        BOOL_NOT                                         ~23     ~22
         33      > JMPZ                                                     ~23, ->39
   25    34    >   ECHO                                                     'WAT%3A+'
         35        INIT_FCALL                                               'var_dump'
         36        SEND_VAR                                                 !3
         37        DO_ICALL                                                 
         38      > JMP                                                      ->43
   27    39    >   ECHO                                                     'OK%3A+'
         40        INIT_FCALL                                               'var_dump'
         41        SEND_VAR                                                 !3
         42        DO_ICALL                                                 
   23    43    > > JMP                                                      ->30
         44    >   FE_FREE                                                  $21
   31    45        INIT_FCALL                                               'json_encode'
         46        SEND_VAR                                                 !4
         47        SEND_VAL                                                 128
         48        DO_ICALL                                         $26     
         49        ECHO                                                     $26
   44    50      > RETURN                                                   1

Function wfrandomstring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 4
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 4
Branch analysis from position: 15
Branch analysis from position: 4
filename:       /in/odIiW
function name:  wfRandomString
number of ops:  24
compiled vars:  !0 = $length, !1 = $str, !2 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1        ASSIGN                                                   !1, ''
   40     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->13
   41     4    >   INIT_FCALL                                               'sprintf'
          5        SEND_VAL                                                 '%2507x'
          6        INIT_FCALL                                               'mt_rand'
          7        DO_ICALL                                         $5      
          8        BW_AND                                           ~6      $5, 268435455
          9        SEND_VAL                                                 ~6
         10        DO_ICALL                                         $7      
         11        ASSIGN_OP                                     8          !1, $7
   40    12        ASSIGN_OP                                     1          !2, 7
         13    >   IS_SMALLER                                               !2, !0
         14      > JMPNZ                                                    ~10, ->4
   43    15    >   INIT_FCALL                                               'substr'
         16        SEND_VAR                                                 !1
         17        SEND_VAL                                                 0
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $11     
         20        VERIFY_RETURN_TYPE                                       $11
         21      > RETURN                                                   $11
   44    22*       VERIFY_RETURN_TYPE                                       
         23*     > RETURN                                                   null

End of function wfrandomstring

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.59 ms | 1404 KiB | 25 Q