3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Generate a random string, using a cryptographically secure * pseudorandom number generator (random_int) * * For PHP 7, random_int is a PHP core function * For PHP 5.x, depends on https://github.com/paragonie/random_compat * * @param int $length How many characters do we want? * @param string $keyspace A string of all possible characters * to select from * @return string */ function random_str($length, $keyspace = '975013246') { $str = ''; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $str .= $keyspace[random_int(0, $max)]; } return $str; } var_dump(random_str(6));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nj2SV
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'random_str'
          2        SEND_VAL                                                 6
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Function random_str:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 11
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 11
Branch analysis from position: 20
Branch analysis from position: 11
filename:       /in/Nj2SV
function name:  random_str
number of ops:  22
compiled vars:  !0 = $length, !1 = $keyspace, !2 = $str, !3 = $max, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '975013246'
   20     2        ASSIGN                                                   !2, ''
   21     3        INIT_FCALL                                               'mb_strlen'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 '8bit'
          6        DO_ICALL                                         $6      
          7        SUB                                              ~7      $6, 1
          8        ASSIGN                                                   !3, ~7
   22     9        ASSIGN                                                   !4, 0
         10      > JMP                                                      ->18
   23    11    >   INIT_FCALL                                               'random_int'
         12        SEND_VAL                                                 0
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                         $10     
         15        FETCH_DIM_R                                      ~11     !1, $10
         16        ASSIGN_OP                                     8          !2, ~11
   22    17        PRE_INC                                                  !4
         18    >   IS_SMALLER                                               !4, !0
         19      > JMPNZ                                                    ~14, ->11
   25    20    > > RETURN                                                   !2
   26    21*     > RETURN                                                   null

End of function random_str

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.44 ms | 1399 KiB | 20 Q