3v4l.org

run code in 300+ PHP versions simultaneously
<?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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3sguX
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  114     0  E >   NEW                                              $0      'IDN'
          1        DO_FCALL                                      0          
          2        INIT_METHOD_CALL                                         $0, 'decodeIDN'
          3        SEND_VAL_EX                                              'xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n'
          4        DO_FCALL                                      0  $2      
          5        ECHO                                                     $2
          6      > RETURN                                                   1

Class IDN:
Function adaptbias:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 14
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 14
Branch analysis from position: 20
Branch analysis from position: 14
Branch analysis from position: 7
1 jumps found. (Code = 42) 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_OP                                     1          !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_OP                                     1          !4, 36
         18    >   IS_SMALLER                                               455, !0
         19      > JMPNZ                                                    ~16, ->14
   13    20    >   MUL                                              ~17     !0, 36
         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
2 jumps found. (Code = 44) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 27
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 42
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) 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                                               !0, 128
          2      > JMPNZ                                                    ~2, ->10
   22     3    >   IS_SMALLER                                               !0, 2048
          4      > JMPNZ                                                    ~3, ->16
   25     5    >   IS_SMALLER                                               !0, 65536
          6      > JMPNZ                                                    ~4, ->27
   28     7    >   IS_SMALLER                                               !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
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 38
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
2 jumps found. (Code = 44) Position 1 = 125, Position 2 = 47
Branch analysis from position: 125
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 96
Branch analysis from position: 96
2 jumps found. (Code = 44) Position 1 = 97, Position 2 = 51
Branch analysis from position: 97
2 jumps found. (Code = 44) Position 1 = 125, Position 2 = 47
Branch analysis from position: 125
Branch analysis from position: 47
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 55
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
2 jumps found. (Code = 46) Position 1 = 63, Position 2 = 65
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 68
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 82
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 92
Branch analysis from position: 91
1 jumps found. (Code = 42) Position 1 = 97
Branch analysis from position: 97
Branch analysis from position: 92
2 jumps found. (Code = 44) Position 1 = 97, Position 2 = 51
Branch analysis from position: 97
Branch analysis from position: 51
Branch analysis from position: 82
2 jumps found. (Code = 43) Position 1 = 85, Position 2 = 87
Branch analysis from position: 85
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
Branch analysis from position: 87
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 92
Branch analysis from position: 91
Branch analysis from position: 92
Branch analysis from position: 68
2 jumps found. (Code = 46) Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 75
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
Branch analysis from position: 65
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
filename:       /in/3sguX
function name:  decodePart
number of ops:  131
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                                         $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        TYPE_CHECK                                  1018          ~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                                                      ->123
   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                         0  ~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_VAL                                                 ~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_OP                                     2          !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_OP                                     2          !12, 22
         74      > JMP                                                      ->76
   70    75    > > RETURN                                                   <false>
   73    76    >   MUL                                              ~51     !12, !10
         77        ASSIGN_OP                                     1          !5, ~51
   75    78        IS_SMALLER_OR_EQUAL                                      !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                                      ~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                                               !12, !13
         90      > JMPZ                                                     ~60, ->92
   84    91    > > JMP                                                      ->97
   87    92    >   SUB                                              ~61     36, !13
         93        CAST                                          4  ~62     ~61
         94        ASSIGN_OP                                     3          !10, ~62
   88    95        ASSIGN_OP                                     1          !11, 36
   58    96    > > JMPNZ                                                    <true>, ->51
   91    97    >   COUNT                                            ~65     !2
         98        ADD                                              ~66     ~65, 1
         99        ASSIGN                                                   !14, ~66
   93   100        INIT_METHOD_CALL                                         'adaptBias'
        101        SUB                                              ~68     !5, !9
        102        SEND_VAL                                                 ~68
        103        SEND_VAR                                                 !14
        104        IS_IDENTICAL                                     ~69     !9, 0
        105        SEND_VAL                                                 ~69
        106        DO_FCALL                                      0  $70     
        107        ASSIGN                                                   !6, $70
   94   108        DIV                                              ~72     !5, !14
        109        CAST                                          4  ~73     ~72
        110        ASSIGN_OP                                     1          !4, ~73
   95   111        ASSIGN_OP                                     5          !5, !14
   97   112        INIT_FCALL                                               'array_splice'
        113        SEND_REF                                                 !2
        114        SEND_VAR                                                 !5
        115        SEND_VAL                                                 0
        116        INIT_METHOD_CALL                                         'encodeUtf8CodePoint'
        117        SEND_VAR                                                 !4
        118        DO_FCALL                                      0  $76     
        119        INIT_ARRAY                                       ~77     $76
        120        SEND_VAL                                                 ~77
        121        DO_ICALL                                                 
   53   122        PRE_INC                                                  !5
        123    >   IS_SMALLER                                               !7, !8
        124      > JMPNZ                                                    ~80, ->47
  100   125    >   INIT_FCALL                                               'implode'
        126        SEND_VAL                                                 ''
        127        SEND_VAR                                                 !2
        128        DO_ICALL                                         $81     
        129      > RETURN                                                   $81
  101   130*     > RETURN                                                   null

End of function decodepart

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

End of function decodeidn

End of class IDN.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.36 ms | 1420 KiB | 31 Q