3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class IDN { private function adaptBias($delta, $numpoints, $first) { $delta = $first ? $delta / 700 : $delta / 2; $delta += $delta / $numPoints; for ($k = 0; $delta > 455; $k += 36) { $delta = (int)($delta / 35); } return $k + (36 * $delta) / ($delta + 38); } private function encodeUtf8CodePoint($codePoint) { switch (true) { case $codePoint < 0x80: return pack('C*', $codePoint & 0x7F); case $codePoint < 0x0800: return pack('C*', (($codePoint & 0x07C0) >> 6) | 0xC0, ($codePoint & 0x3F) | 0x80); case $codePoint < 0x010000: return pack('C*', (($codePoint & 0xF000) >> 12) | 0xE0, (($codePoint & 0x0FC0) >> 6) | 0x80, ($codePoint & 0x3F) | 0x80); case $codePoint < 0x110000: return pack('C*', (($codePoint & 0x1C0000) >> 18) | 0xF0, (($codePoint & 0x03F000) >> 12) | 0x80, (($codePoint & 0x0FC0) >> 6) | 0x80, ($codePoint & 0x3F) | 0x80); } return false; } public function decodePart($input) { if (substr($input, 0, 4) !== 'xn--') { return $input; } $input = substr($input, 4); if (false !== $nonBasicCharsStart = strrpos($input, '-')) { $output = str_split(substr($input, 0, $nonBasicCharsStart), 1); $nonBasicChars = substr($input, $nonBasicCharsStart + 1); } else { $output = []; $nonBasicChars = $input; } $n = 128; $i = 0; $bias = 72; for ($j = 0, $l = strlen($nonBasicChars); $j < $l; $i++) { $oldi = $i; $w = 1; $k = 36; while (true) { if (!isset($nonBasicChars[$j])) { return false; } $digit = ord($nonBasicChars[$j++]); if ($digit >= 0x61 && $digit <= 0x7A) { $digit -= 97; } else if ($digit >= 0x30 && $digit <= 0x39) { $digit -= 22; } else { return false; } $i += $digit * $w; if ($k <= $bias) { $t = 1; } else if ($k >= $bias + 26) { $t = 26; } else { $t = $k - $bias; } if ($digit < $t) { break; } $w *= (int) (36 - $t); $k += 36; } $c = count($output) + 1; $bias = $this->adaptBias($i - $oldi, $c, $oldi === 0); $n += (int)($i / $c); $i %= $c; array_splice($output, $i, 0, array($this->encodeUtf8CodePoint($n))); } return implode('', $output); } public function decodeIDN($name) { // split it, parse it and put it back together return implode( ".", array_map([$this, 'decodePart'],explode(".",$name)) ); } } echo (new IDN)->decodeIDN("xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n");
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/3sguX
function name:  (null)
number of ops:  8
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   NOP                                                      
 114     1        NEW                                              $1      :-6
         2        DO_FCALL                                      0          
         3        INIT_METHOD_CALL                                         $1, 'decodeIDN'
         4        SEND_VAL_EX                                              'xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n'
         5        DO_FCALL                                      0  $3      
         6        ECHO                                                     $3
         7      > RETURN                                                   1

Class IDN:
Function adaptbias:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
Jump found. Position 1 = 9
Branch analysis from position: 9
Jump found. Position 1 = 18
Branch analysis from position: 18
Jump found. Position 1 = 20, Position 2 = 14
Branch analysis from position: 20
Jump found. Position 1 = -2
Branch analysis from position: 14
Jump found. Position 1 = 20, Position 2 = 14
Branch analysis from position: 20
Branch analysis from position: 14
Branch analysis from position: 7
Jump found. Position 1 = 18
Branch analysis from position: 18
filename:       /in/3sguX
function name:  adaptBias
number of ops:  26
compiled vars:  !0 = $delta, !1 = $numpoints, !2 = $first, !3 = $numPoints, !4 = $k
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   4     0  E >   RECV                                             !0      
         1        RECV                                             !1      
         2        RECV                                             !2      
   6     3      > JMPZ                                                     !2, ->7
         4    >   DIV                                              ~5      !0, 700
         5        QM_ASSIGN                                        ~6      ~5
         6      > JMP                                                      ->9
         7    >   DIV                                              ~7      !0, 2
         8        QM_ASSIGN                                        ~6      ~7
         9    >   ASSIGN                                                   !0, ~6
   7    10        DIV                                              ~9      !0, !3
        11        ASSIGN_ADD                                    0          !0, ~9
   9    12        ASSIGN                                                   !4, 0
        13      > JMP                                                      ->18
  10    14    >   DIV                                              ~12     !0, 35
        15        CAST                                          4  ~13     ~12
        16        ASSIGN                                                   !0, ~13
   9    17        ASSIGN_ADD                                    0          !4, 36
        18    >   IS_SMALLER                                       ~16     455, !0
        19      > JMPNZ                                                    ~16, ->14
  13    20    >   MUL                                              ~17     36, !0
        21        ADD                                              ~18     !0, 38
        22        DIV                                              ~19     ~17, ~18
        23        ADD                                              ~20     !4, ~19
        24      > RETURN                                                   ~20
  14    25*     > RETURN                                                   null

End of function adaptbias

Function encodeutf8codepoint:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
Jump found. Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
Jump found. Position 1 = 7, Position 2 = 27
Branch analysis from position: 7
Jump found. Position 1 = 9, Position 2 = 42
Branch analysis from position: 9
Jump found. Position 1 = 61
Branch analysis from position: 61
Jump found. Position 1 = -2
Branch analysis from position: 42
Jump found. Position 1 = -2
Branch analysis from position: 27
Jump found. Position 1 = -2
Branch analysis from position: 16
Jump found. Position 1 = -2
Branch analysis from position: 10
Jump found. Position 1 = -2
filename:       /in/3sguX
function name:  encodeUtf8CodePoint
number of ops:  63
compiled vars:  !0 = $codePoint
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  16     0  E >   RECV                                             !0      
  19     1        IS_SMALLER                                       ~2      !0, 128
         2      > JMPNZ                                                    ~2, ->10
  22     3    >   IS_SMALLER                                       ~3      !0, 2048
         4      > JMPNZ                                                    ~3, ->16
  25     5    >   IS_SMALLER                                       ~4      !0, 65536
         6      > JMPNZ                                                    ~4, ->27
  28     7    >   IS_SMALLER                                       ~5      !0, 1114112
         8      > JMPNZ                                                    ~5, ->42
         9    > > JMP                                                      ->61
  20    10    >   INIT_FCALL                                               'pack'
        11        SEND_VAL                                                 'C%2A'
        12        BW_AND                                           ~6      !0, 127
        13        SEND_VAL                                                 ~6
        14        DO_ICALL                                         $7      
        15      > RETURN                                                   $7
  23    16    >   INIT_FCALL                                               'pack'
        17        SEND_VAL                                                 'C%2A'
        18        BW_AND                                           ~8      !0, 1984
        19        SR                                               ~9      ~8, 6
        20        BW_OR                                            ~10     ~9, 192
        21        SEND_VAL                                                 ~10
        22        BW_AND                                           ~11     !0, 63
        23        BW_OR                                            ~12     ~11, 128
        24        SEND_VAL                                                 ~12
        25        DO_ICALL                                         $13     
        26      > RETURN                                                   $13
  26    27    >   INIT_FCALL                                               'pack'
        28        SEND_VAL                                                 'C%2A'
        29        BW_AND                                           ~14     !0, 61440
        30        SR                                               ~15     ~14, 12
        31        BW_OR                                            ~16     ~15, 224
        32        SEND_VAL                                                 ~16
        33        BW_AND                                           ~17     !0, 4032
        34        SR                                               ~18     ~17, 6
        35        BW_OR                                            ~19     ~18, 128
        36        SEND_VAL                                                 ~19
        37        BW_AND                                           ~20     !0, 63
        38        BW_OR                                            ~21     ~20, 128
        39        SEND_VAL                                                 ~21
        40        DO_ICALL                                         $22     
        41      > RETURN                                                   $22
  29    42    >   INIT_FCALL                                               'pack'
        43        SEND_VAL                                                 'C%2A'
        44        BW_AND                                           ~23     !0, 1835008
        45        SR                                               ~24     ~23, 18
        46        BW_OR                                            ~25     ~24, 240
        47        SEND_VAL                                                 ~25
        48        BW_AND                                           ~26     !0, 258048
        49        SR                                               ~27     ~26, 12
        50        BW_OR                                            ~28     ~27, 128
        51        SEND_VAL                                                 ~28
        52        BW_AND                                           ~29     !0, 4032
        53        SR                                               ~30     ~29, 6
        54        BW_OR                                            ~31     ~30, 128
        55        SEND_VAL                                                 ~31
        56        BW_AND                                           ~32     !0, 63
        57        BW_OR                                            ~33     ~32, 128
        58        SEND_VAL                                                 ~33
        59        DO_ICALL                                         $34     
        60      > RETURN                                                   $34
  32    61    > > RETURN                                                   <false>
  33    62*     > RETURN                                                   null

End of function encodeutf8codepoint

Function decodepart:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
Jump found. Position 1 = -2
Branch analysis from position: 9
Jump found. Position 1 = 21, Position 2 = 38
Branch analysis from position: 21
Jump found. Position 1 = 40
Branch analysis from position: 40
Jump found. Position 1 = 126
Branch analysis from position: 126
Jump found. Position 1 = 128, Position 2 = 47
Branch analysis from position: 128
Jump found. Position 1 = -2
Branch analysis from position: 47
Jump found. Position 1 = 96
Branch analysis from position: 96
Jump found. Position 1 = 97, Position 2 = 51
Branch analysis from position: 97
Jump found. Position 1 = 128, Position 2 = 47
Branch analysis from position: 128
Branch analysis from position: 47
Branch analysis from position: 51
Jump found. Position 1 = 54, Position 2 = 55
Branch analysis from position: 54
Jump found. Position 1 = -2
Branch analysis from position: 55
Jump found. Position 1 = 63, Position 2 = 65
Branch analysis from position: 63
Jump found. Position 1 = 66, Position 2 = 68
Branch analysis from position: 66
Jump found. Position 1 = 76
Branch analysis from position: 76
Jump found. Position 1 = 80, Position 2 = 82
Branch analysis from position: 80
Jump found. Position 1 = 89
Branch analysis from position: 89
Jump found. Position 1 = 91, Position 2 = 92
Branch analysis from position: 91
Jump found. Position 1 = 97
Branch analysis from position: 97
Branch analysis from position: 92
Jump found. Position 1 = 97, Position 2 = 51
Branch analysis from position: 97
Branch analysis from position: 51
Branch analysis from position: 82
Jump found. Position 1 = 85, Position 2 = 87
Branch analysis from position: 85
Jump found. Position 1 = 89
Branch analysis from position: 89
Branch analysis from position: 87
Jump found. Position 1 = 91, Position 2 = 92
Branch analysis from position: 91
Branch analysis from position: 92
Branch analysis from position: 68
Jump found. Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
Jump found. Position 1 = 73, Position 2 = 75
Branch analysis from position: 73
Jump found. Position 1 = 76
Branch analysis from position: 76
Branch analysis from position: 75
Jump found. Position 1 = -2
Branch analysis from position: 72
Branch analysis from position: 65
Branch analysis from position: 38
Jump found. Position 1 = 126
Branch analysis from position: 126
filename:       /in/3sguX
function name:  decodePart
number of ops:  134
compiled vars:  !0 = $input, !1 = $nonBasicCharsStart, !2 = $output, !3 = $nonBasicChars, !4 = $n, !5 = $i, !6 = $bias, !7 = $j, !8 = $l, !9 = $oldi, !10 = $w, !11 = $k, !12 = $digit, !13 = $t, !14 = $c
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  35     0  E >   RECV                                             !0      
  36     1        INIT_FCALL                                               'substr'
         2        SEND_VAR                                                 !0
         3        SEND_VAL                                                 0
         4        SEND_VAL                                                 4
         5        DO_ICALL                                         $15     
         6        IS_NOT_IDENTICAL                                 ~16     $15, 'xn--'
         7      > JMPZ                                                     ~16, ->9
  37     8    > > RETURN                                                   !0
  39     9    >   INIT_FCALL                                               'substr'
        10        SEND_VAR                                                 !0
        11        SEND_VAL                                                 4
        12        DO_ICALL                                         $17     
        13        ASSIGN                                                   !0, $17
  41    14        INIT_FCALL                                               'strrpos'
        15        SEND_VAR                                                 !0
        16        SEND_VAL                                                 '-'
        17        DO_ICALL                                         $19     
        18        ASSIGN                                           $20     !1, $19
        19        IS_NOT_IDENTICAL                                 ~21     <false>, $20
        20      > JMPZ                                                     ~21, ->38
  42    21    >   INIT_FCALL                                               'str_split'
        22        INIT_FCALL                                               'substr'
        23        SEND_VAR                                                 !0
        24        SEND_VAL                                                 0
        25        SEND_VAR                                                 !1
        26        DO_ICALL                                         $22     
        27        SEND_VAR                                                 $22
        28        SEND_VAL                                                 1
        29        DO_ICALL                                         $23     
        30        ASSIGN                                                   !2, $23
  43    31        INIT_FCALL                                               'substr'
        32        SEND_VAR                                                 !0
        33        ADD                                              ~25     !1, 1
        34        SEND_VAL                                                 ~25
        35        DO_ICALL                                         $26     
        36        ASSIGN                                                   !3, $26
        37      > JMP                                                      ->40
  45    38    >   ASSIGN                                                   !2, <array>
  46    39        ASSIGN                                                   !3, !0
  49    40    >   ASSIGN                                                   !4, 128
  50    41        ASSIGN                                                   !5, 0
  51    42        ASSIGN                                                   !6, 72
  53    43        ASSIGN                                                   !7, 0
        44        STRLEN                                           ~34     !3
        45        ASSIGN                                                   !8, ~34
        46      > JMP                                                      ->126
  54    47    >   ASSIGN                                                   !9, !5
  55    48        ASSIGN                                                   !10, 1
  56    49        ASSIGN                                                   !11, 36
  58    50      > JMP                                                      ->96
  59    51    >   ISSET_ISEMPTY_DIM_OBJ                       33554432  ~39     !3, !7
        52        BOOL_NOT                                         ~40     ~39
        53      > JMPZ                                                     ~40, ->55
  60    54    > > RETURN                                                   <false>
  63    55    >   INIT_FCALL                                               'ord'
        56        POST_INC                                         ~41     !7
        57        FETCH_DIM_R                                      $42     !3, ~41
        58        SEND_VAR                                                 $42
        59        DO_ICALL                                         $43     
        60        ASSIGN                                                   !12, $43
  65    61        IS_SMALLER_OR_EQUAL                              ~45     97, !12
        62      > JMPZ_EX                                          ~45     ~45, ->65
        63    >   IS_SMALLER_OR_EQUAL                              ~46     !12, 122
        64        BOOL                                             ~45     ~46
        65    > > JMPZ                                                     ~45, ->68
  66    66    >   ASSIGN_SUB                                    0          !12, 97
        67      > JMP                                                      ->76
  67    68    >   IS_SMALLER_OR_EQUAL                              ~48     48, !12
        69      > JMPZ_EX                                          ~48     ~48, ->72
        70    >   IS_SMALLER_OR_EQUAL                              ~49     !12, 57
        71        BOOL                                             ~48     ~49
        72    > > JMPZ                                                     ~48, ->75
  68    73    >   ASSIGN_SUB                                    0          !12, 22
        74      > JMP                                                      ->76
  70    75    > > RETURN                                                   <false>
  73    76    >   MUL                                              ~51     !12, !10
        77        ASSIGN_ADD                                    0          !5, ~51
  75    78        IS_SMALLER_OR_EQUAL                              ~53     !11, !6
        79      > JMPZ                                                     ~53, ->82
  76    80    >   ASSIGN                                                   !13, 1
        81      > JMP                                                      ->89
  77    82    >   ADD                                              ~55     !6, 26
        83        IS_SMALLER_OR_EQUAL                              ~56     ~55, !11
        84      > JMPZ                                                     ~56, ->87
  78    85    >   ASSIGN                                                   !13, 26
        86      > JMP                                                      ->89
  80    87    >   SUB                                              ~58     !11, !6
        88        ASSIGN                                                   !13, ~58
  83    89    >   IS_SMALLER                                       ~60     !12, !13
        90      > JMPZ                                                     ~60, ->92
  84    91    > > JMP                                                      ->97
  87    92    >   SUB                                              ~61     36, !13
        93        CAST                                          4  ~62     ~61
        94        ASSIGN_MUL                                    0          !10, ~62
  88    95        ASSIGN_ADD                                    0          !11, 36
  58    96    > > JMPNZ                                                    <true>, ->51
  91    97    >   INIT_FCALL                                               'count'
        98        SEND_VAR                                                 !2
        99        DO_ICALL                                         $65     
       100        ADD                                              ~66     $65, 1
       101        ASSIGN                                                   !14, ~66
  93   102        INIT_METHOD_CALL                                         'adaptBias'
       103        SUB                                              ~68     !5, !9
       104        SEND_VAL_EX                                              ~68
       105        SEND_VAR_EX                                              !14
       106        IS_IDENTICAL                                     ~69     !9, 0
       107        SEND_VAL_EX                                              ~69
       108        DO_FCALL                                      0  $70     
       109        ASSIGN                                                   !6, $70
  94   110        DIV                                              ~72     !5, !14
       111        CAST                                          4  ~73     ~72
       112        ASSIGN_ADD                                    0          !4, ~73
  95   113        ASSIGN_MOD                                    0          !5, !14
  97   114        INIT_FCALL                                               'array_splice'
       115        SEND_REF                                                 !2
       116        SEND_VAR                                                 !5
       117        SEND_VAL                                                 0
       118        INIT_METHOD_CALL                                         'encodeUtf8CodePoint'
       119        SEND_VAR_EX                                              !4
       120        DO_FCALL                                      0  $76     
       121        INIT_ARRAY                                       ~77     $76
       122        SEND_VAL                                                 ~77
       123        DO_ICALL                                                 
  53   124        POST_INC                                         ~79     !5
       125        FREE                                                     ~79
       126    >   IS_SMALLER                                       ~80     !7, !8
       127      > JMPNZ                                                    ~80, ->47
 100   128    >   INIT_FCALL                                               'implode'
       129        SEND_VAL                                                 ''
       130        SEND_VAR                                                 !2
       131        DO_ICALL                                         $81     
       132      > RETURN                                                   $81
 101   133*     > RETURN                                                   null

End of function decodepart

Function decodeidn:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/3sguX
function name:  decodeIDN
number of ops:  17
compiled vars:  !0 = $name, !1 = $this
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
 103     0  E >   RECV                                             !0      
 106     1        INIT_FCALL                                               'implode'
 107     2        SEND_VAL                                                 '.'
         3        INIT_FCALL                                               'array_map'
 108     4        INIT_ARRAY                                       ~2      !1
         5        ADD_ARRAY_ELEMENT                                ~2      'decodePart'
         6        SEND_VAL                                                 ~2
         7        INIT_FCALL                                               'explode'
         8        SEND_VAL                                                 '.'
         9        SEND_VAR                                                 !0
        10        DO_ICALL                                         $3      
        11        SEND_VAR                                                 $3
        12        DO_ICALL                                         $4      
        13        SEND_VAR                                                 $4
        14        DO_ICALL                                         $5      
        15      > RETURN                                                   $5
 110    16*     > RETURN                                                   null

End of function decodeidn

End of class IDN.

Generated using Vulcan Logic Dumper, using php 7.2.0