3v4l.org

run code in 300+ PHP versions simultaneously
<?php function convertToBytes(string $from): ?int { $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; $number = substr($from, 0, -2); $suffix = strtoupper(substr($from,-2)); //B or no suffix if(is_numeric(substr($suffix, 0, 1))) { return preg_replace('/[^\d]/', '', $from); } $exponent = array_flip($units)[$suffix] ?? null; if($exponent === null) { return null; } return $number * (1024 ** $exponent); } var_dump(convertToBytes("110GB"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6SNq9
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'converttobytes'
          2        SEND_VAL                                                 '110GB'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Function converttobytes:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 42
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6SNq9
function name:  convertToBytes
number of ops:  48
compiled vars:  !0 = $from, !1 = $units, !2 = $number, !3 = $suffix, !4 = $exponent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        INIT_FCALL                                               'substr'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 0
          5        SEND_VAL                                                 -2
          6        DO_ICALL                                         $6      
          7        ASSIGN                                                   !2, $6
    6     8        INIT_FCALL                                               'strtoupper'
          9        INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 -2
         12        DO_ICALL                                         $8      
         13        SEND_VAR                                                 $8
         14        DO_ICALL                                         $9      
         15        ASSIGN                                                   !3, $9
    9    16        INIT_FCALL                                               'is_numeric'
         17        INIT_FCALL                                               'substr'
         18        SEND_VAR                                                 !3
         19        SEND_VAL                                                 0
         20        SEND_VAL                                                 1
         21        DO_ICALL                                         $11     
         22        SEND_VAR                                                 $11
         23        DO_ICALL                                         $12     
         24      > JMPZ                                                     $12, ->32
   10    25    >   INIT_FCALL                                               'preg_replace'
         26        SEND_VAL                                                 '%2F%5B%5E%5Cd%5D%2F'
         27        SEND_VAL                                                 ''
         28        SEND_VAR                                                 !0
         29        DO_ICALL                                         $13     
         30        VERIFY_RETURN_TYPE                                       $13
         31      > RETURN                                                   $13
   13    32    >   INIT_FCALL                                               'array_flip'
         33        SEND_VAR                                                 !1
         34        DO_ICALL                                         $14     
         35        FETCH_DIM_IS                                     ~15     $14, !3
         36        COALESCE                                         ~16     ~15
         37        QM_ASSIGN                                        ~16     null
         38        ASSIGN                                                   !4, ~16
   14    39        TYPE_CHECK                                    2          !4
         40      > JMPZ                                                     ~18, ->42
   15    41    > > RETURN                                                   null
   18    42    >   POW                                              ~19     1024, !4
         43        MUL                                              ~20     !2, ~19
         44        VERIFY_RETURN_TYPE                                       ~20
         45      > RETURN                                                   ~20
   19    46*       VERIFY_RETURN_TYPE                                       
         47*     > RETURN                                                   null

End of function converttobytes

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.53 ms | 1023 KiB | 20 Q