3v4l.org

run code in 300+ PHP versions simultaneously
<?php // https://www.strangebuzz.com/en/snippets/convert-a-string-into-an-array-of-characters $tokenSize = 32; try { $random = random_bytes($tokenSize); } catch (\Exception $e) { throw new \RuntimeException('Unable to get random_bytes.'); } $base = base64_encode($random); $clean = str_replace(str_split('+/-_'), '', $base); $cut = substr($clean, 0, $tokenSize); echo 'Token: '.$cut."\n"; echo 'Token length: '.strlen($cut);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 6
Branch analysis from position: 6
2 jumps found. (Code = 107) Position 1 = 7, Position 2 = -2
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/vn6so
function name:  (null)
number of ops:  37
compiled vars:  !0 = $tokenSize, !1 = $random, !2 = $e, !3 = $base, !4 = $clean, !5 = $cut
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, 32
    7     1        INIT_FCALL                                               'random_bytes'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $7      
          4        ASSIGN                                                   !1, $7
          5      > JMP                                                      ->11
    8     6  E > > CATCH                                       last         'Exception'
    9     7    >   NEW                                              $9      'RuntimeException'
          8        SEND_VAL_EX                                              'Unable+to+get+random_bytes.'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $9
   11    11    >   INIT_FCALL                                               'base64_encode'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $11     
         14        ASSIGN                                                   !3, $11
   12    15        INIT_FCALL                                               'str_replace'
         16        INIT_FCALL                                               'str_split'
         17        SEND_VAL                                                 '%2B%2F-_'
         18        DO_ICALL                                         $13     
         19        SEND_VAR                                                 $13
         20        SEND_VAL                                                 ''
         21        SEND_VAR                                                 !3
         22        DO_ICALL                                         $14     
         23        ASSIGN                                                   !4, $14
   13    24        INIT_FCALL                                               'substr'
         25        SEND_VAR                                                 !4
         26        SEND_VAL                                                 0
         27        SEND_VAR                                                 !0
         28        DO_ICALL                                         $16     
         29        ASSIGN                                                   !5, $16
   15    30        CONCAT                                           ~18     'Token%3A+', !5
         31        CONCAT                                           ~19     ~18, '%0A'
         32        ECHO                                                     ~19
   16    33        STRLEN                                           ~20     !5
         34        CONCAT                                           ~21     'Token+length%3A+', ~20
         35        ECHO                                                     ~21
         36      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.64 ms | 1465 KiB | 18 Q