3v4l.org

run code in 300+ PHP versions simultaneously
<?php class UUID { public static function v3($namespace, $name) { if(!self::is_valid($namespace)) return false; // Get hexadecimal components of namespace $nhex = str_replace(array('-','{','}'), '', $namespace); // Binary Value $nstr = ''; // Convert Namespace UUID to bits for($i = 0; $i < strlen($nhex); $i+=2) { $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1])); } // Calculate hash value $hash = md5($nstr . $name); return sprintf('%08s-%04s-%04x-%04x-%12s', // 32 bits for "time_low" substr($hash, 0, 8), // 16 bits for "time_mid" substr($hash, 8, 4), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 3 (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000, // 48 bits for "node" substr($hash, 20, 12) ); } public static function v4() { return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', // 32 bits for "time_low" mt_rand(0, 0xffff), mt_rand(0, 0xffff), // 16 bits for "time_mid" mt_rand(0, 0xffff), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 4 mt_rand(0, 0x0fff) | 0x4000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 mt_rand(0, 0x3fff) | 0x8000, // 48 bits for "node" mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); } public static function v5($namespace, $name) { if(!self::is_valid($namespace)) return false; // Get hexadecimal components of namespace $nhex = str_replace(array('-','{','}'), '', $namespace); // Binary Value $nstr = ''; // Convert Namespace UUID to bits for($i = 0; $i < strlen($nhex); $i+=2) { $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1])); } // Calculate hash value $hash = sha1($nstr . $name); return sprintf('%08s-%04s-%04x-%04x-%12s', // 32 bits for "time_low" substr($hash, 0, 8), // 16 bits for "time_mid" substr($hash, 8, 4), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 5 (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000, // 48 bits for "node" substr($hash, 20, 12) ); } public static function is_valid($uuid) { return preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'. '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $uuid) === 1; } } // Usage // Named-based UUID. print UUID::v5('1546058f-5a25-4334-85ae-e68f2a44bbaf', 'SomeRandomString'); // Pseudo-random UUID ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/haRUv
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  113     0  E >   INIT_STATIC_METHOD_CALL                                  'UUID', 'v5'
          1        SEND_VAL                                                 '1546058f-5a25-4334-85ae-e68f2a44bbaf'
          2        SEND_VAL                                                 'SomeRandomString'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
  117     5      > RETURN                                                   1

Class UUID:
Function v3:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 17
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 17
Branch analysis from position: 32
Branch analysis from position: 17
filename:       /in/haRUv
function name:  v3
number of ops:  82
compiled vars:  !0 = $namespace, !1 = $name, !2 = $nhex, !3 = $nstr, !4 = $i, !5 = $hash
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_STATIC_METHOD_CALL                                  'is_valid'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $6      
          5        BOOL_NOT                                         ~7      $6
          6      > JMPZ                                                     ~7, ->8
          7    > > RETURN                                                   <false>
    7     8    >   INIT_FCALL                                               'str_replace'
          9        SEND_VAL                                                 <array>
         10        SEND_VAL                                                 ''
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $8      
         13        ASSIGN                                                   !2, $8
   10    14        ASSIGN                                                   !3, ''
   13    15        ASSIGN                                                   !4, 0
         16      > JMP                                                      ->29
   14    17    >   INIT_FCALL                                               'chr'
         18        INIT_FCALL                                               'hexdec'
         19        FETCH_DIM_R                                      ~12     !2, !4
         20        ADD                                              ~13     !4, 1
         21        FETCH_DIM_R                                      ~14     !2, ~13
         22        CONCAT                                           ~15     ~12, ~14
         23        SEND_VAL                                                 ~15
         24        DO_ICALL                                         $16     
         25        SEND_VAR                                                 $16
         26        DO_ICALL                                         $17     
         27        ASSIGN_OP                                     8          !3, $17
   13    28        ASSIGN_OP                                     1          !4, 2
         29    >   STRLEN                                           ~20     !2
         30        IS_SMALLER                                               !4, ~20
         31      > JMPNZ                                                    ~21, ->17
   18    32    >   INIT_FCALL                                               'md5'
         33        CONCAT                                           ~22     !3, !1
         34        SEND_VAL                                                 ~22
         35        DO_ICALL                                         $23     
         36        ASSIGN                                                   !5, $23
   20    37        INIT_FCALL                                               'sprintf'
         38        SEND_VAL                                                 '%2508s-%2504s-%2504x-%2504x-%2512s'
   23    39        INIT_FCALL                                               'substr'
         40        SEND_VAR                                                 !5
         41        SEND_VAL                                                 0
         42        SEND_VAL                                                 8
         43        DO_ICALL                                         $25     
         44        SEND_VAR                                                 $25
   26    45        INIT_FCALL                                               'substr'
         46        SEND_VAR                                                 !5
         47        SEND_VAL                                                 8
         48        SEND_VAL                                                 4
         49        DO_ICALL                                         $26     
         50        SEND_VAR                                                 $26
   30    51        INIT_FCALL                                               'hexdec'
         52        INIT_FCALL                                               'substr'
         53        SEND_VAR                                                 !5
         54        SEND_VAL                                                 12
         55        SEND_VAL                                                 4
         56        DO_ICALL                                         $27     
         57        SEND_VAR                                                 $27
         58        DO_ICALL                                         $28     
         59        BW_AND                                           ~29     $28, 4095
         60        BW_OR                                            ~30     ~29, 12288
         61        SEND_VAL                                                 ~30
   35    62        INIT_FCALL                                               'hexdec'
         63        INIT_FCALL                                               'substr'
         64        SEND_VAR                                                 !5
         65        SEND_VAL                                                 16
         66        SEND_VAL                                                 4
         67        DO_ICALL                                         $31     
         68        SEND_VAR                                                 $31
         69        DO_ICALL                                         $32     
         70        BW_AND                                           ~33     $32, 16383
         71        BW_OR                                            ~34     ~33, 32768
         72        SEND_VAL                                                 ~34
   38    73        INIT_FCALL                                               'substr'
         74        SEND_VAR                                                 !5
         75        SEND_VAL                                                 20
         76        SEND_VAL                                                 12
         77        DO_ICALL                                         $35     
         78        SEND_VAR                                                 $35
         79        DO_ICALL                                         $36     
         80      > RETURN                                                   $36
   40    81*     > RETURN                                                   null

End of function v3

Function v4:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/haRUv
function name:  v4
number of ops:  47
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   INIT_FCALL                                               'sprintf'
          1        SEND_VAL                                                 '%2504x%2504x-%2504x-%2504x-%2504x-%2504x%2504x%2504x'
   46     2        INIT_FCALL                                               'mt_rand'
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 65535
          5        DO_ICALL                                         $0      
          6        SEND_VAR                                                 $0
          7        INIT_FCALL                                               'mt_rand'
          8        SEND_VAL                                                 0
          9        SEND_VAL                                                 65535
         10        DO_ICALL                                         $1      
         11        SEND_VAR                                                 $1
   49    12        INIT_FCALL                                               'mt_rand'
         13        SEND_VAL                                                 0
         14        SEND_VAL                                                 65535
         15        DO_ICALL                                         $2      
         16        SEND_VAR                                                 $2
   53    17        INIT_FCALL                                               'mt_rand'
         18        SEND_VAL                                                 0
         19        SEND_VAL                                                 4095
         20        DO_ICALL                                         $3      
         21        BW_OR                                            ~4      $3, 16384
         22        SEND_VAL                                                 ~4
   58    23        INIT_FCALL                                               'mt_rand'
         24        SEND_VAL                                                 0
         25        SEND_VAL                                                 16383
         26        DO_ICALL                                         $5      
         27        BW_OR                                            ~6      $5, 32768
         28        SEND_VAL                                                 ~6
   61    29        INIT_FCALL                                               'mt_rand'
         30        SEND_VAL                                                 0
         31        SEND_VAL                                                 65535
         32        DO_ICALL                                         $7      
         33        SEND_VAR                                                 $7
         34        INIT_FCALL                                               'mt_rand'
         35        SEND_VAL                                                 0
         36        SEND_VAL                                                 65535
         37        DO_ICALL                                         $8      
         38        SEND_VAR                                                 $8
         39        INIT_FCALL                                               'mt_rand'
         40        SEND_VAL                                                 0
         41        SEND_VAL                                                 65535
         42        DO_ICALL                                         $9      
         43        SEND_VAR                                                 $9
         44        DO_ICALL                                         $10     
         45      > RETURN                                                   $10
   63    46*     > RETURN                                                   null

End of function v4

Function v5:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 17
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 17
Branch analysis from position: 32
Branch analysis from position: 17
filename:       /in/haRUv
function name:  v5
number of ops:  82
compiled vars:  !0 = $namespace, !1 = $name, !2 = $nhex, !3 = $nstr, !4 = $i, !5 = $hash
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   66     2        INIT_STATIC_METHOD_CALL                                  'is_valid'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $6      
          5        BOOL_NOT                                         ~7      $6
          6      > JMPZ                                                     ~7, ->8
          7    > > RETURN                                                   <false>
   69     8    >   INIT_FCALL                                               'str_replace'
          9        SEND_VAL                                                 <array>
         10        SEND_VAL                                                 ''
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $8      
         13        ASSIGN                                                   !2, $8
   72    14        ASSIGN                                                   !3, ''
   75    15        ASSIGN                                                   !4, 0
         16      > JMP                                                      ->29
   76    17    >   INIT_FCALL                                               'chr'
         18        INIT_FCALL                                               'hexdec'
         19        FETCH_DIM_R                                      ~12     !2, !4
         20        ADD                                              ~13     !4, 1
         21        FETCH_DIM_R                                      ~14     !2, ~13
         22        CONCAT                                           ~15     ~12, ~14
         23        SEND_VAL                                                 ~15
         24        DO_ICALL                                         $16     
         25        SEND_VAR                                                 $16
         26        DO_ICALL                                         $17     
         27        ASSIGN_OP                                     8          !3, $17
   75    28        ASSIGN_OP                                     1          !4, 2
         29    >   STRLEN                                           ~20     !2
         30        IS_SMALLER                                               !4, ~20
         31      > JMPNZ                                                    ~21, ->17
   80    32    >   INIT_FCALL                                               'sha1'
         33        CONCAT                                           ~22     !3, !1
         34        SEND_VAL                                                 ~22
         35        DO_ICALL                                         $23     
         36        ASSIGN                                                   !5, $23
   82    37        INIT_FCALL                                               'sprintf'
         38        SEND_VAL                                                 '%2508s-%2504s-%2504x-%2504x-%2512s'
   85    39        INIT_FCALL                                               'substr'
         40        SEND_VAR                                                 !5
         41        SEND_VAL                                                 0
         42        SEND_VAL                                                 8
         43        DO_ICALL                                         $25     
         44        SEND_VAR                                                 $25
   88    45        INIT_FCALL                                               'substr'
         46        SEND_VAR                                                 !5
         47        SEND_VAL                                                 8
         48        SEND_VAL                                                 4
         49        DO_ICALL                                         $26     
         50        SEND_VAR                                                 $26
   92    51        INIT_FCALL                                               'hexdec'
         52        INIT_FCALL                                               'substr'
         53        SEND_VAR                                                 !5
         54        SEND_VAL                                                 12
         55        SEND_VAL                                                 4
         56        DO_ICALL                                         $27     
         57        SEND_VAR                                                 $27
         58        DO_ICALL                                         $28     
         59        BW_AND                                           ~29     $28, 4095
         60        BW_OR                                            ~30     ~29, 20480
         61        SEND_VAL                                                 ~30
   97    62        INIT_FCALL                                               'hexdec'
         63        INIT_FCALL                                               'substr'
         64        SEND_VAR                                                 !5
         65        SEND_VAL                                                 16
         66        SEND_VAL                                                 4
         67        DO_ICALL                                         $31     
         68        SEND_VAR                                                 $31
         69        DO_ICALL                                         $32     
         70        BW_AND                                           ~33     $32, 16383
         71        BW_OR                                            ~34     ~33, 32768
         72        SEND_VAL                                                 ~34
  100    73        INIT_FCALL                                               'substr'
         74        SEND_VAR                                                 !5
         75        SEND_VAL                                                 20
         76        SEND_VAL                                                 12
         77        DO_ICALL                                         $35     
         78        SEND_VAR                                                 $35
         79        DO_ICALL                                         $36     
         80      > RETURN                                                   $36
  102    81*     > RETURN                                                   null

End of function v5

Function is_valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/haRUv
function name:  is_valid
number of ops:  8
compiled vars:  !0 = $uuid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  104     0  E >   RECV                                             !0      
  105     1        INIT_FCALL                                               'preg_match'
  106     2        SEND_VAL                                                 '%2F%5E%5C%7B%3F%5B0-9a-f%5D%7B8%7D%5C-%3F%5B0-9a-f%5D%7B4%7D%5C-%3F%5B0-9a-f%5D%7B4%7D%5C-%3F%5B0-9a-f%5D%7B4%7D%5C-%3F%5B0-9a-f%5D%7B12%7D%5C%7D%3F%24%2Fi'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        IS_IDENTICAL                                     ~2      $1, 1
          6      > RETURN                                                   ~2
  107     7*     > RETURN                                                   null

End of function is_valid

End of class UUID.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.29 ms | 1416 KiB | 31 Q