3v4l.org

run code in 300+ PHP versions simultaneously
<?php $ip = '127.0.0.1'; function test($ip) { if (false !== strpos($ip, '/')) { list($address, $netmask) = explode('/', $ip, 2); if ($netmask < 1 || $netmask > 32) { return false; } } else { $address = $ip; $netmask = 32; } $netmask = str_pad(str_pad('', $netmask, '1'), 32, '0'); $in_addr = ''; foreach(array_map('bindec', str_split($netmask, 8)) as $char) { $in_addr .= pack('C*', $char); } $netmask = inet_pton(inet_ntop($in_addr)); $network = inet_pton($address) & $netmask; return [$network, inet_ntop($network | ~$netmask)]; } var_dump(test('127.0.0.1')); var_dump(test('10.0.0.3/29'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r6kHT
function name:  (null)
number of ops:  14
compiled vars:  !0 = $ip
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '127.0.0.1'
   28     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'test'
          3        SEND_VAL                                                 '127.0.0.1'
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
   29     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'test'
          9        SEND_VAL                                                 '10.0.0.3%2F29'
         10        DO_FCALL                                      0  $4      
         11        SEND_VAR                                                 $4
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function test:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
2 jumps found. (Code = 47) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 77) Position 1 = 47, Position 2 = 54
Branch analysis from position: 47
2 jumps found. (Code = 78) Position 1 = 48, Position 2 = 54
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
Branch analysis from position: 21
Branch analysis from position: 24
2 jumps found. (Code = 77) Position 1 = 47, Position 2 = 54
Branch analysis from position: 47
Branch analysis from position: 54
filename:       /in/r6kHT
function name:  test
number of ops:  76
compiled vars:  !0 = $ip, !1 = $address, !2 = $netmask, !3 = $in_addr, !4 = $char, !5 = $network
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'strpos'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%2F'
          4        DO_ICALL                                         $6      
          5        TYPE_CHECK                                  1018          $6
          6      > JMPZ                                                     ~7, ->24
    6     7    >   INIT_FCALL                                               'explode'
          8        SEND_VAL                                                 '%2F'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 2
         11        DO_ICALL                                         $8      
         12        FETCH_LIST_R                                     $9      $8, 0
         13        ASSIGN                                                   !1, $9
         14        FETCH_LIST_R                                     $11     $8, 1
         15        ASSIGN                                                   !2, $11
         16        FREE                                                     $8
    8    17        IS_SMALLER                                       ~13     !2, 1
         18      > JMPNZ_EX                                         ~13     ~13, ->21
         19    >   IS_SMALLER                                       ~14     32, !2
         20        BOOL                                             ~13     ~14
         21    > > JMPZ                                                     ~13, ->23
    9    22    > > RETURN                                                   <false>
         23    > > JMP                                                      ->26
   12    24    >   ASSIGN                                                   !1, !0
   13    25        ASSIGN                                                   !2, 32
   16    26    >   INIT_FCALL                                               'str_pad'
         27        INIT_FCALL                                               'str_pad'
         28        SEND_VAL                                                 ''
         29        SEND_VAR                                                 !2
         30        SEND_VAL                                                 '1'
         31        DO_ICALL                                         $17     
         32        SEND_VAR                                                 $17
         33        SEND_VAL                                                 32
         34        SEND_VAL                                                 '0'
         35        DO_ICALL                                         $18     
         36        ASSIGN                                                   !2, $18
   17    37        ASSIGN                                                   !3, ''
   19    38        INIT_FCALL                                               'array_map'
         39        SEND_VAL                                                 'bindec'
         40        INIT_FCALL                                               'str_split'
         41        SEND_VAR                                                 !2
         42        SEND_VAL                                                 8
         43        DO_ICALL                                         $21     
         44        SEND_VAR                                                 $21
         45        DO_ICALL                                         $22     
         46      > FE_RESET_R                                       $23     $22, ->54
         47    > > FE_FETCH_R                                               $23, !4, ->54
   20    48    >   INIT_FCALL                                               'pack'
         49        SEND_VAL                                                 'C%2A'
         50        SEND_VAR                                                 !4
         51        DO_ICALL                                         $24     
         52        ASSIGN_OP                                     8          !3, $24
   19    53      > JMP                                                      ->47
         54    >   FE_FREE                                                  $23
   23    55        INIT_FCALL                                               'inet_pton'
         56        INIT_FCALL                                               'inet_ntop'
         57        SEND_VAR                                                 !3
         58        DO_ICALL                                         $26     
         59        SEND_VAR                                                 $26
         60        DO_ICALL                                         $27     
         61        ASSIGN                                                   !2, $27
   24    62        INIT_FCALL                                               'inet_pton'
         63        SEND_VAR                                                 !1
         64        DO_ICALL                                         $29     
         65        BW_AND                                           ~30     !2, $29
         66        ASSIGN                                                   !5, ~30
   25    67        INIT_ARRAY                                       ~32     !5
         68        INIT_FCALL                                               'inet_ntop'
         69        BW_NOT                                           ~33     !2
         70        BW_OR                                            ~34     !5, ~33
         71        SEND_VAL                                                 ~34
         72        DO_ICALL                                         $35     
         73        ADD_ARRAY_ELEMENT                                ~32     $35
         74      > RETURN                                                   ~32
   26    75*     > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.63 ms | 1398 KiB | 33 Q