3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('random_bytes')) { function random_bytes($size) { if(!is_int($size)) throw new InvalidArgumentException('random_bytes: $size must be an int'); if($size < 0) throw new InvalidArgumentException('random_bytes: $size must not be negative'); //if(function_exists('mcrypt_create_iv')) //{ // $result = mcrypt_create_iv($size, MCRYPT_DEV_URANDOM); //} else if(function_exists('openssl_random_pseudo_bytes')) { $result = openssl_random_pseudo_bytes($size, $isSecure); var_dump($isSecure); if(!$isSecure) { throw new RuntimeException("random_bytes: openssl_random_pseudo_bytes returned insecure data"); } } else { throw new RuntimeException("random_bytes: No RNG found"); } if(!is_string($result) || (strlen($result) !== $size)) { throw new RuntimeException("random_bytes: RNG is unavailable or broken"); } return $result; } } if (!function_exists('random_int')) { function random_int($min, $max) { if(!defined('PHP_INT_SIZE')) trigger_error("random_int: This version of PHP is not supported", E_USER_ERROR); if(!is_int($min)) throw new InvalidArgumentException('random_int: $min must be an int'); if(!is_int($min)) throw new InvalidArgumentException('random_int: $min must be an int'); if($min > $max) throw new InvalidArgumentException('random_int: $min must be less or equal to $max'); $range = $max - $min + 1; // the rejection probability is at most 0.5, so this corresponds to a failure probability of 2^-128 for a working RNG for($attempts = 0; $attempts < 128; $attempts++) { // generate a random integer $bytes = random_bytes(PHP_INT_SIZE); $value = 0; for($i = 0; $i < PHP_INT_SIZE; $i++) { $value = ($value << 8) | ord($bytes[$i]); } if(!is_int($range)) { if(($value >= $min) && ($value <= $max)) { return $value; } } else { $value &= PHP_INT_MAX; // equivalent to (PHP_INT_MAX + 1) % range, but avoids int overflows // I'm assuming PHP_INT_MAX + 1 is a power-of-two $reject = (-$range & PHP_INT_MAX) % $range; if($value >= $reject) { return ($value % $range) + $min; } } } throw new RuntimeException("random_int: RNG is broken - too many rejections"); } } random_int(0, 1000);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
Branch analysis from position: 6
filename:       /in/jJ6Qv
function name:  (null)
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'function_exists'
          1        SEND_VAL                                                 'random_bytes'
          2        DO_ICALL                                         $0      
          3        BOOL_NOT                                         ~1      $0
          4      > JMPZ                                                     ~1, ->6
    4     5    >   DECLARE_FUNCTION                                         'random_bytes'
   37     6    >   INIT_FCALL                                               'function_exists'
          7        SEND_VAL                                                 'random_int'
          8        DO_ICALL                                         $2      
          9        BOOL_NOT                                         ~3      $2
         10      > JMPZ                                                     ~3, ->12
   38    11    >   DECLARE_FUNCTION                                         'random_int'
   82    12    >   INIT_FCALL                                               'random_int'
         13        SEND_VAL                                                 0
         14        SEND_VAL                                                 1000
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Function %00random_bytes%2Fin%2FjJ6Qv%3A4%240:
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 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 34
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 33
Branch analysis from position: 29
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 47) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 49
Branch analysis from position: 45
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 34
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/jJ6Qv
function name:  random_bytes
number of ops:  51
compiled vars:  !0 = $size, !1 = $result, !2 = $isSecure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        TYPE_CHECK                                   16  ~3      !0
          2        BOOL_NOT                                         ~4      ~3
          3      > JMPZ                                                     ~4, ->8
    7     4    >   NEW                                              $5      'InvalidArgumentException'
          5        SEND_VAL_EX                                              'random_bytes%3A+%24size+must+be+an+int'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $5
    8     8    >   IS_SMALLER                                               !0, 0
          9      > JMPZ                                                     ~7, ->15
    9    10    >   NEW                                              $8      'InvalidArgumentException'
         11        SEND_VAL_EX                                              'random_bytes%3A+%24size+must+not+be+negative'
         12        DO_FCALL                                      0          
         13      > THROW                                         0          $8
         14*       JMP                                                      ->38
   15    15    >   INIT_FCALL                                               'function_exists'
         16        SEND_VAL                                                 'openssl_random_pseudo_bytes'
         17        DO_ICALL                                         $10     
         18      > JMPZ                                                     $10, ->34
   17    19    >   INIT_FCALL_BY_NAME                                       'openssl_random_pseudo_bytes'
         20        SEND_VAR_EX                                              !0
         21        SEND_VAR_EX                                              !2
         22        DO_FCALL                                      0  $11     
         23        ASSIGN                                                   !1, $11
   18    24        INIT_FCALL                                               'var_dump'
         25        SEND_VAR                                                 !2
         26        DO_ICALL                                                 
   19    27        BOOL_NOT                                         ~14     !2
         28      > JMPZ                                                     ~14, ->33
   21    29    >   NEW                                              $15     'RuntimeException'
         30        SEND_VAL_EX                                              'random_bytes%3A+openssl_random_pseudo_bytes+returned+insecure+data'
         31        DO_FCALL                                      0          
         32      > THROW                                         0          $15
         33    > > JMP                                                      ->38
   26    34    >   NEW                                              $17     'RuntimeException'
         35        SEND_VAL_EX                                              'random_bytes%3A+No+RNG+found'
         36        DO_FCALL                                      0          
         37      > THROW                                         0          $17
   29    38    >   TYPE_CHECK                                   64  ~19     !1
         39        BOOL_NOT                                         ~20     ~19
         40      > JMPNZ_EX                                         ~20     ~20, ->44
         41    >   STRLEN                                           ~21     !1
         42        IS_NOT_IDENTICAL                                 ~22     !0, ~21
         43        BOOL                                             ~20     ~22
         44    > > JMPZ                                                     ~20, ->49
   31    45    >   NEW                                              $23     'RuntimeException'
         46        SEND_VAL_EX                                              'random_bytes%3A+RNG+is+unavailable+or+broken'
         47        DO_FCALL                                      0          
         48      > THROW                                         0          $23
   33    49    > > RETURN                                                   !1
   34    50*     > RETURN                                                   null

End of function %00random_bytes%2Fin%2FjJ6Qv%3A4%240

Function %00random_int%2Fin%2FjJ6Qv%3A38%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
2 jumps found. (Code = 44) Position 1 = 72, Position 2 = 32
Branch analysis from position: 72
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 39
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 59
Branch analysis from position: 52
2 jumps found. (Code = 46) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 58
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 72, Position 2 = 32
Branch analysis from position: 72
Branch analysis from position: 32
Branch analysis from position: 56
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 69
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 39
Branch analysis from position: 49
Branch analysis from position: 39
Branch analysis from position: 7
filename:       /in/jJ6Qv
function name:  random_int
number of ops:  77
compiled vars:  !0 = $min, !1 = $max, !2 = $range, !3 = $attempts, !4 = $bytes, !5 = $value, !6 = $i, !7 = $reject
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   40     2      > JMPZ                                                     <false>, ->7
   41     3    >   INIT_FCALL                                               'trigger_error'
          4        SEND_VAL                                                 'random_int%3A+This+version+of+PHP+is+not+supported'
          5        SEND_VAL                                                 256
          6        DO_ICALL                                                 
   42     7    >   TYPE_CHECK                                   16  ~9      !0
          8        BOOL_NOT                                         ~10     ~9
          9      > JMPZ                                                     ~10, ->14
   43    10    >   NEW                                              $11     'InvalidArgumentException'
         11        SEND_VAL_EX                                              'random_int%3A+%24min+must+be+an+int'
         12        DO_FCALL                                      0          
         13      > THROW                                         0          $11
   44    14    >   TYPE_CHECK                                   16  ~13     !0
         15        BOOL_NOT                                         ~14     ~13
         16      > JMPZ                                                     ~14, ->21
   45    17    >   NEW                                              $15     'InvalidArgumentException'
         18        SEND_VAL_EX                                              'random_int%3A+%24min+must+be+an+int'
         19        DO_FCALL                                      0          
         20      > THROW                                         0          $15
   46    21    >   IS_SMALLER                                               !1, !0
         22      > JMPZ                                                     ~17, ->27
   47    23    >   NEW                                              $18     'InvalidArgumentException'
         24        SEND_VAL_EX                                              'random_int%3A+%24min+must+be+less+or+equal+to+%24max'
         25        DO_FCALL                                      0          
         26      > THROW                                         0          $18
   49    27    >   SUB                                              ~20     !1, !0
         28        ADD                                              ~21     ~20, 1
         29        ASSIGN                                                   !2, ~21
   51    30        ASSIGN                                                   !3, 0
         31      > JMP                                                      ->70
   54    32    >   INIT_FCALL                                               'random_bytes'
         33        SEND_VAL                                                 8
         34        DO_ICALL                                         $24     
         35        ASSIGN                                                   !4, $24
   55    36        ASSIGN                                                   !5, 0
   56    37        ASSIGN                                                   !6, 0
         38      > JMP                                                      ->47
   58    39    >   SL                                               ~28     !5, 8
         40        INIT_FCALL                                               'ord'
         41        FETCH_DIM_R                                      ~29     !4, !6
         42        SEND_VAL                                                 ~29
         43        DO_ICALL                                         $30     
         44        BW_OR                                            ~31     $30, ~28
         45        ASSIGN                                                   !5, ~31
   56    46        PRE_INC                                                  !6
         47    >   IS_SMALLER                                               !6, 8
         48      > JMPNZ                                                    ~34, ->39
   61    49    >   TYPE_CHECK                                   16  ~35     !2
         50        BOOL_NOT                                         ~36     ~35
         51      > JMPZ                                                     ~36, ->59
   63    52    >   IS_SMALLER_OR_EQUAL                              ~37     !0, !5
         53      > JMPZ_EX                                          ~37     ~37, ->56
         54    >   IS_SMALLER_OR_EQUAL                              ~38     !5, !1
         55        BOOL                                             ~37     ~38
         56    > > JMPZ                                                     ~37, ->58
   65    57    > > RETURN                                                   !5
         58    > > JMP                                                      ->69
   68    59    >   ASSIGN_OP                                    10          !5, 9223372036854775807
   71    60        MUL                                              ~40     !2, -1
         61        BW_AND                                           ~41     ~40, 9223372036854775807
         62        MOD                                              ~42     ~41, !2
         63        ASSIGN                                                   !7, ~42
   72    64        IS_SMALLER_OR_EQUAL                                      !7, !5
         65      > JMPZ                                                     ~44, ->69
   74    66    >   MOD                                              ~45     !5, !2
         67        ADD                                              ~46     ~45, !0
         68      > RETURN                                                   ~46
   51    69    >   PRE_INC                                                  !3
         70    >   IS_SMALLER                                               !3, 128
         71      > JMPNZ                                                    ~48, ->32
   78    72    >   NEW                                              $49     'RuntimeException'
         73        SEND_VAL_EX                                              'random_int%3A+RNG+is+broken+-+too+many+rejections'
         74        DO_FCALL                                      0          
         75      > THROW                                         0          $49
   79    76*     > RETURN                                                   null

End of function %00random_int%2Fin%2FjJ6Qv%3A38%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.7 ms | 1412 KiB | 25 Q