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); if($isSecure !== true) { 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/s2cvp
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'
   36     6    >   INIT_FCALL                                               'function_exists'
          7        SEND_VAL                                                 'random_int'
          8        DO_ICALL                                         $2      
          9        BOOL_NOT                                         ~3      $2
         10      > JMPZ                                                     ~3, ->12
   37    11    >   DECLARE_FUNCTION                                         'random_int'
   81    12    >   INIT_FCALL                                               'random_int'
         13        SEND_VAL                                                 0
         14        SEND_VAL                                                 1000
         15        DO_ICALL                                                 
         16      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
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 = 31
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 47) Position 1 = 38, Position 2 = 41
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 46
Branch analysis from position: 42
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
Branch analysis from position: 31
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/s2cvp
function name:  random_bytes
number of ops:  48
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
    8    14*       JMP                                                      ->35
   15    15    >   INIT_FCALL                                               'function_exists'
         16        SEND_VAL                                                 'openssl_random_pseudo_bytes'
         17        DO_ICALL                                         $10     
         18      > JMPZ                                                     $10, ->31
   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        TYPE_CHECK                                  1014          !2
         25      > JMPZ                                                     ~13, ->30
   20    26    >   NEW                                              $14     'RuntimeException'
         27        SEND_VAL_EX                                              'random_bytes%3A+openssl_random_pseudo_bytes+returned+insecure+data'
         28        DO_FCALL                                      0          
         29      > THROW                                         0          $14
   15    30    > > JMP                                                      ->35
   25    31    >   NEW                                              $16     'RuntimeException'
         32        SEND_VAL_EX                                              'random_bytes%3A+No+RNG+found'
         33        DO_FCALL                                      0          
         34      > THROW                                         0          $16
   28    35    >   TYPE_CHECK                                   64  ~18     !1
         36        BOOL_NOT                                         ~19     ~18
         37      > JMPNZ_EX                                         ~19     ~19, ->41
         38    >   STRLEN                                           ~20     !1
         39        IS_NOT_IDENTICAL                                 ~21     !0, ~20
         40        BOOL                                             ~19     ~21
         41    > > JMPZ                                                     ~19, ->46
   30    42    >   NEW                                              $22     'RuntimeException'
         43        SEND_VAL_EX                                              'random_bytes%3A+RNG+is+unavailable+or+broken'
         44        DO_FCALL                                      0          
         45      > THROW                                         0          $22
   32    46    > > RETURN                                                   !1
   33    47*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
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/s2cvp
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
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   39     2      > JMPZ                                                     <false>, ->7
   40     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                                                 
   41     7    >   TYPE_CHECK                                   16  ~9      !0
          8        BOOL_NOT                                         ~10     ~9
          9      > JMPZ                                                     ~10, ->14
   42    10    >   NEW                                              $11     'InvalidArgumentException'
         11        SEND_VAL_EX                                              'random_int%3A+%24min+must+be+an+int'
         12        DO_FCALL                                      0          
         13      > THROW                                         0          $11
   43    14    >   TYPE_CHECK                                   16  ~13     !0
         15        BOOL_NOT                                         ~14     ~13
         16      > JMPZ                                                     ~14, ->21
   44    17    >   NEW                                              $15     'InvalidArgumentException'
         18        SEND_VAL_EX                                              'random_int%3A+%24min+must+be+an+int'
         19        DO_FCALL                                      0          
         20      > THROW                                         0          $15
   45    21    >   IS_SMALLER                                               !1, !0
         22      > JMPZ                                                     ~17, ->27
   46    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
   48    27    >   SUB                                              ~20     !1, !0
         28        ADD                                              ~21     ~20, 1
         29        ASSIGN                                                   !2, ~21
   50    30        ASSIGN                                                   !3, 0
         31      > JMP                                                      ->70
   53    32    >   INIT_FCALL                                               'random_bytes'
         33        SEND_VAL                                                 8
         34        DO_ICALL                                         $24     
         35        ASSIGN                                                   !4, $24
   54    36        ASSIGN                                                   !5, 0
   55    37        ASSIGN                                                   !6, 0
         38      > JMP                                                      ->47
   57    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
   55    46        PRE_INC                                                  !6
         47    >   IS_SMALLER                                               !6, 8
         48      > JMPNZ                                                    ~34, ->39
   60    49    >   TYPE_CHECK                                   16  ~35     !2
         50        BOOL_NOT                                         ~36     ~35
         51      > JMPZ                                                     ~36, ->59
   62    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
   64    57    > > RETURN                                                   !5
   60    58    > > JMP                                                      ->69
   67    59    >   ASSIGN_OP                                    10          !5, 9223372036854775807
   70    60        MUL                                              ~40     !2, -1
         61        BW_AND                                           ~41     ~40, 9223372036854775807
         62        MOD                                              ~42     ~41, !2
         63        ASSIGN                                                   !7, ~42
   71    64        IS_SMALLER_OR_EQUAL                                      !7, !5
         65      > JMPZ                                                     ~44, ->69
   73    66    >   MOD                                              ~45     !5, !2
         67        ADD                                              ~46     ~45, !0
         68      > RETURN                                                   ~46
   50    69    >   PRE_INC                                                  !3
         70    >   IS_SMALLER                                               !3, 128
         71      > JMPNZ                                                    ~48, ->32
   77    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
   78    76*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.25 ms | 1454 KiB | 18 Q