3v4l.org

run code in 300+ PHP versions simultaneously
<?php function random_string($length = 26, $alphabet = 'abcdefghijklmnopqrstuvwxyz234567') { if ($length < 1) { throw new InvalidArgumentException('Length must be a positive integer'); } $str = ''; $alphamax = strlen($alphabet) - 1; if ($alphamax < 1) { throw new InvalidArgumentException('Invalid alphabet'); } for ($i = 0; $i < $length; ++$i) { $str .= $alphabet[random_int(0, $alphamax)]; } return $str; } var_dump( random_string(), random_string(128), random_string(52, '0123456789abcdef') );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DOjNE
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_FCALL                                               'var_dump'
   20     1        INIT_FCALL                                               'random_string'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
   21     4        INIT_FCALL                                               'random_string'
          5        SEND_VAL                                                 128
          6        DO_FCALL                                      0  $1      
          7        SEND_VAR                                                 $1
   22     8        INIT_FCALL                                               'random_string'
          9        SEND_VAL                                                 52
         10        SEND_VAL                                                 '0123456789abcdef'
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                                 
   23    14      > RETURN                                                   1

Function random_string:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 20
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 20
Branch analysis from position: 29
Branch analysis from position: 20
filename:       /in/DOjNE
function name:  random_string
number of ops:  31
compiled vars:  !0 = $length, !1 = $alphabet, !2 = $str, !3 = $alphamax, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV_INIT                                        !0      26
          1        RECV_INIT                                        !1      'abcdefghijklmnopqrstuvwxyz234567'
    5     2        IS_SMALLER                                               !0, 1
          3      > JMPZ                                                     ~5, ->8
    6     4    >   NEW                                              $6      'InvalidArgumentException'
          5        SEND_VAL_EX                                              'Length+must+be+a+positive+integer'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $6
    8     8    >   ASSIGN                                                   !2, ''
    9     9        STRLEN                                           ~9      !1
         10        SUB                                              ~10     ~9, 1
         11        ASSIGN                                                   !3, ~10
   10    12        IS_SMALLER                                               !3, 1
         13      > JMPZ                                                     ~12, ->18
   11    14    >   NEW                                              $13     'InvalidArgumentException'
         15        SEND_VAL_EX                                              'Invalid+alphabet'
         16        DO_FCALL                                      0          
         17      > THROW                                         0          $13
   13    18    >   ASSIGN                                                   !4, 0
         19      > JMP                                                      ->27
   14    20    >   INIT_FCALL                                               'random_int'
         21        SEND_VAL                                                 0
         22        SEND_VAR                                                 !3
         23        DO_ICALL                                         $16     
         24        FETCH_DIM_R                                      ~17     !1, $16
         25        ASSIGN_OP                                     8          !2, ~17
   13    26        PRE_INC                                                  !4
         27    >   IS_SMALLER                                               !4, !0
         28      > JMPNZ                                                    ~20, ->20
   16    29    > > RETURN                                                   !2
   17    30*     > RETURN                                                   null

End of function random_string

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.12 ms | 1403 KiB | 20 Q