3v4l.org

run code in 300+ PHP versions simultaneously
<?php function is_ip($ip, $version = null) { switch ($version) { case 4: if (filter_var($ip, FILTER_VALIDATE_IP, array('flags' => array(FILTER_FLAG_IPV4, FILTER_FLAG_NO_PRIV_RANGE, FILTER_FLAG_NO_RES_RANGE))) !== false) { return "passed <br />\n"; } break; case 6: if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) { return "passed <br />\n"; } break; case 'bug': if (filter_var($ip, FILTER_VALIDATE_IP, array('flags' => array(FILTER_FLAG_IPV6, FILTER_FLAG_NO_PRIV_RANGE))) !== false) { return "passed <br />\n"; } break; default: if (filter_var($ip, FILTER_VALIDATE_IP, array('flags' => array(FILTER_FLAG_IPV4, FILTER_FLAG_IPV6, FILTER_FLAG_NO_PRIV_RANGE, FILTER_FLAG_NO_RES_RANGE))) !== false) { return "passed <br />\n"; } break; } return "didn't pass <br />\n"; } $ip = "127.0.0.1"; echo "IP address validation test: " . $ip . "<br />\n"; echo "v4: ". is_ip($ip, 4); echo "v6: ". is_ip($ip, 6); echo "v6: ". is_ip($ip, 'bug'); echo "v4 or v6: ". is_ip($ip);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hAgXm
function name:  (null)
number of ops:  28
compiled vars:  !0 = $ip
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ASSIGN                                                   !0, '127.0.0.1'
   31     1        CONCAT                                           ~2      'IP+address+validation+test%3A+', !0
          2        CONCAT                                           ~3      ~2, '%3Cbr+%2F%3E%0A'
          3        ECHO                                                     ~3
   32     4        INIT_FCALL                                               'is_ip'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 4
          7        DO_FCALL                                      0  $4      
          8        CONCAT                                           ~5      'v4%3A+', $4
          9        ECHO                                                     ~5
   33    10        INIT_FCALL                                               'is_ip'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 6
         13        DO_FCALL                                      0  $6      
         14        CONCAT                                           ~7      'v6%3A+', $6
         15        ECHO                                                     ~7
   34    16        INIT_FCALL                                               'is_ip'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 'bug'
         19        DO_FCALL                                      0  $8      
         20        CONCAT                                           ~9      'v6%3A+', $8
         21        ECHO                                                     ~9
   35    22        INIT_FCALL                                               'is_ip'
         23        SEND_VAR                                                 !0
         24        DO_FCALL                                      0  $10     
         25        CONCAT                                           ~11     'v4+or+v6%3A+', $10
         26        ECHO                                                     ~11
         27      > RETURN                                                   1

Function is_ip:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 27
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 44
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 35
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
filename:       /in/hAgXm
function name:  is_ip
number of ops:  47
compiled vars:  !0 = $ip, !1 = $version
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    5     2        IS_EQUAL                                                 !1, 4
          3      > JMPNZ                                                    ~2, ->9
   10     4    >   IS_EQUAL                                                 !1, 6
          5      > JMPNZ                                                    ~2, ->18
   15     6    >   IS_EQUAL                                                 !1, 'bug'
          7      > JMPNZ                                                    ~2, ->27
          8    > > JMP                                                      ->36
    6     9    >   INIT_FCALL                                               'filter_var'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 275
         12        SEND_VAL                                                 <array>
         13        DO_ICALL                                         $3      
         14        TYPE_CHECK                                  1018          $3
         15      > JMPZ                                                     ~4, ->17
    7    16    > > RETURN                                                   'passed+%3Cbr+%2F%3E%0A'
    9    17    > > JMP                                                      ->45
   11    18    >   INIT_FCALL                                               'filter_var'
         19        SEND_VAR                                                 !0
         20        SEND_VAL                                                 275
         21        SEND_VAL                                                 2097152
         22        DO_ICALL                                         $5      
         23        TYPE_CHECK                                  1018          $5
         24      > JMPZ                                                     ~6, ->26
   12    25    > > RETURN                                                   'passed+%3Cbr+%2F%3E%0A'
   14    26    > > JMP                                                      ->45
   16    27    >   INIT_FCALL                                               'filter_var'
         28        SEND_VAR                                                 !0
         29        SEND_VAL                                                 275
         30        SEND_VAL                                                 <array>
         31        DO_ICALL                                         $7      
         32        TYPE_CHECK                                  1018          $7
         33      > JMPZ                                                     ~8, ->35
   17    34    > > RETURN                                                   'passed+%3Cbr+%2F%3E%0A'
   19    35    > > JMP                                                      ->45
   21    36    >   INIT_FCALL                                               'filter_var'
         37        SEND_VAR                                                 !0
         38        SEND_VAL                                                 275
         39        SEND_VAL                                                 <array>
         40        DO_ICALL                                         $9      
         41        TYPE_CHECK                                  1018          $9
         42      > JMPZ                                                     ~10, ->44
   22    43    > > RETURN                                                   'passed+%3Cbr+%2F%3E%0A'
   24    44    > > JMP                                                      ->45
   27    45    > > RETURN                                                   'didn%27t+pass+%3Cbr+%2F%3E%0A'
   28    46*     > RETURN                                                   null

End of function is_ip

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.12 ms | 1021 KiB | 18 Q