3v4l.org

run code in 300+ PHP versions simultaneously
<?php mt_srand(42); for ($i = 0; $i < 20; $i++) { $key = generate_key(64); $len = strlen($key); echo "{$key} {$len}\n"; } function generate_key($n) { $k = ceil($n*0.75); $key = base64_urlencode(rand_buffer($k)); if (strlen($key) > $n) { $key = substr($key, 0, $n); } return $key; } function base64_urlencode($buf) { return str_replace( array('+', '/', '='), array('-', '_', ''), base64_encode($buf) ); } function rand_buffer($n) { if (function_exists("openssl_random_pseudo_bytes")) { return openssl_random_pseudo_bytes($n); } $buf = ""; for ($i = 0; $i < $n; $i++) { $buf .= chr(mt_rand(0, 255)); } return $buf; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 5
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 5
Branch analysis from position: 19
Branch analysis from position: 5
filename:       /in/sd6vi
function name:  (null)
number of ops:  20
compiled vars:  !0 = $i, !1 = $key, !2 = $len
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'mt_srand'
          1        SEND_VAL                                                 42
          2        DO_ICALL                                                 
    5     3        ASSIGN                                                   !0, 0
          4      > JMP                                                      ->17
    6     5    >   INIT_FCALL_BY_NAME                                       'generate_key'
          6        SEND_VAL_EX                                              64
          7        DO_FCALL                                      0  $5      
          8        ASSIGN                                                   !1, $5
    7     9        STRLEN                                           ~7      !1
         10        ASSIGN                                                   !2, ~7
    8    11        ROPE_INIT                                     4  ~10     !1
         12        ROPE_ADD                                      1  ~10     ~10, '+'
         13        ROPE_ADD                                      2  ~10     ~10, !2
         14        ROPE_END                                      3  ~9      ~10, '%0A'
         15        ECHO                                                     ~9
    5    16        PRE_INC                                                  !0
         17    >   IS_SMALLER                                               !0, 20
         18      > JMPNZ                                                    ~13, ->5
   37    19    > > RETURN                                                   1

Function generate_key:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/sd6vi
function name:  generate_key
number of ops:  24
compiled vars:  !0 = $n, !1 = $k, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'ceil'
          2        MUL                                              ~3      !0, 0.75
          3        SEND_VAL                                                 ~3
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
   13     6        INIT_FCALL_BY_NAME                                       'base64_urlencode'
          7        INIT_FCALL_BY_NAME                                       'rand_buffer'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0  $6      
         10        SEND_VAR_NO_REF_EX                                       $6
         11        DO_FCALL                                      0  $7      
         12        ASSIGN                                                   !2, $7
   14    13        STRLEN                                           ~9      !2
         14        IS_SMALLER                                               !0, ~9
         15      > JMPZ                                                     ~10, ->22
   15    16    >   INIT_FCALL                                               'substr'
         17        SEND_VAR                                                 !2
         18        SEND_VAL                                                 0
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $11     
         21        ASSIGN                                                   !2, $11
   17    22    > > RETURN                                                   !2
   18    23*     > RETURN                                                   null

End of function generate_key

Function base64_urlencode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sd6vi
function name:  base64_urlencode
number of ops:  11
compiled vars:  !0 = $buf
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        INIT_FCALL                                               'str_replace'
   22     2        SEND_VAL                                                 <array>
   23     3        SEND_VAL                                                 <array>
   24     4        INIT_FCALL                                               'base64_encode'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $1      
          7        SEND_VAR                                                 $1
          8        DO_ICALL                                         $2      
          9      > RETURN                                                   $2
   26    10*     > RETURN                                                   null

End of function base64_urlencode

Function rand_buffer:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 12
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 12
Branch analysis from position: 23
Branch analysis from position: 12
filename:       /in/sd6vi
function name:  rand_buffer
number of ops:  25
compiled vars:  !0 = $n, !1 = $buf, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   29     1        INIT_FCALL                                               'function_exists'
          2        SEND_VAL                                                 'openssl_random_pseudo_bytes'
          3        DO_ICALL                                         $3      
          4      > JMPZ                                                     $3, ->9
   30     5    >   INIT_FCALL_BY_NAME                                       'openssl_random_pseudo_bytes'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $4      
          8      > RETURN                                                   $4
   32     9    >   ASSIGN                                                   !1, ''
   33    10        ASSIGN                                                   !2, 0
         11      > JMP                                                      ->21
   34    12    >   INIT_FCALL                                               'chr'
         13        INIT_FCALL                                               'mt_rand'
         14        SEND_VAL                                                 0
         15        SEND_VAL                                                 255
         16        DO_ICALL                                         $7      
         17        SEND_VAR                                                 $7
         18        DO_ICALL                                         $8      
         19        ASSIGN_OP                                     8          !1, $8
   33    20        PRE_INC                                                  !2
         21    >   IS_SMALLER                                               !2, !0
         22      > JMPNZ                                                    ~11, ->12
   36    23    > > RETURN                                                   !1
   37    24*     > RETURN                                                   null

End of function rand_buffer

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.22 ms | 1396 KiB | 29 Q