3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('INT_SIGNED', 1); define('INT_LE', 2); function unpack_int32($str, $flags = 0) { $length = strlen($str); if ($length < 4) { return false; } else if ($length > 4) { $str = substr($str, 0, 4); } if ($flags & INT_LE) { $str = strrev($str); } $result = current(unpack('N', $str)); $signBit = (bool) ($result & 0x80000000); $isSigned = (bool) ($flags & INT_SIGNED); $is32bit = PHP_INT_MAX < 0x80000000; if ($signBit && $isSigned && !$is32bit) { $result = 0xFFFFFFFF00000000 | $result; } else if ($signBit && !$isSigned && $is32bit) { $result = (($result & 0x7FFFFFFF) * 2) + ~$result + 1; } return $result; } function unpack_int64($str, $flags = 0) { $length = strlen($str); if ($length < 8) { return false; } else if ($length > 8) { $str = substr($str, 0, 8); } $is32bit = PHP_INT_MAX < 0x80000000; if ($flags & INT_LE) { $str = strrev($str); } $longs = array_values(unpack('NN', substr($str, 0, 4), substr($str, 4, 4))); $signBit = (bool) ($longs[0] & 0x80000000); if (PHP_INT_MAX > 0x7FFFFFFF) { $result = ($longs[0] << 32) | $longs[1]; if ($signBit) { $result = (($result & 0x7FFFFFFFFFFFFFFF) * 2) + ~$result + 1; } } return $result; } var_dump(unpack_int32("\x81\x00\x00\x80", INT_SIGNED | INT_LE));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZfDP3
function name:  (null)
number of ops:  19
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'INT_SIGNED'
          2        SEND_VAL                                                 1
          3        DO_ICALL                                                 
    4     4        INIT_FCALL                                               'define'
          5        SEND_VAL                                                 'INT_LE'
          6        SEND_VAL                                                 2
          7        DO_ICALL                                                 
   59     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'unpack_int32'
         10        SEND_VAL                                                 '%81%00%00%80'
         11        FETCH_CONSTANT                                   ~2      'INT_SIGNED'
         12        FETCH_CONSTANT                                   ~3      'INT_LE'
         13        BW_OR                                            ~4      ~2, ~3
         14        SEND_VAL                                                 ~4
         15        DO_FCALL                                      0  $5      
         16        SEND_VAR                                                 $5
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Function unpack_int32:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 40, Position 2 = 41
Branch analysis from position: 40
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 48
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
2 jumps found. (Code = 46) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
2 jumps found. (Code = 46) Position 1 = 52, Position 2 = 53
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 60
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
Branch analysis from position: 53
Branch analysis from position: 51
Branch analysis from position: 44
Branch analysis from position: 41
Branch analysis from position: 23
Branch analysis from position: 16
filename:       /in/ZfDP3
function name:  unpack_int32
number of ops:  62
compiled vars:  !0 = $str, !1 = $flags, !2 = $length, !3 = $result, !4 = $signBit, !5 = $isSigned, !6 = $is32bit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
    7     2        STRLEN                                           ~7      !0
          3        ASSIGN                                                   !2, ~7
    8     4        IS_SMALLER                                               !2, 4
          5      > JMPZ                                                     ~9, ->8
    9     6    > > RETURN                                                   <false>
          7*       JMP                                                      ->16
   10     8    >   IS_SMALLER                                               4, !2
          9      > JMPZ                                                     ~10, ->16
   11    10    >   INIT_FCALL                                               'substr'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 4
         14        DO_ICALL                                         $11     
         15        ASSIGN                                                   !0, $11
   14    16    >   FETCH_CONSTANT                                   ~13     'INT_LE'
         17        BW_AND                                           ~14     !1, ~13
         18      > JMPZ                                                     ~14, ->23
   15    19    >   INIT_FCALL                                               'strrev'
         20        SEND_VAR                                                 !0
         21        DO_ICALL                                         $15     
         22        ASSIGN                                                   !0, $15
   17    23    >   INIT_FCALL                                               'current'
         24        INIT_FCALL                                               'unpack'
         25        SEND_VAL                                                 'N'
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $17     
         28        SEND_VAR                                                 $17
         29        DO_ICALL                                         $18     
         30        ASSIGN                                                   !3, $18
   19    31        BW_AND                                           ~20     !3, 2147483648
         32        BOOL                                             ~21     ~20
         33        ASSIGN                                                   !4, ~21
   20    34        FETCH_CONSTANT                                   ~23     'INT_SIGNED'
         35        BW_AND                                           ~24     !1, ~23
         36        BOOL                                             ~25     ~24
         37        ASSIGN                                                   !5, ~25
   21    38        ASSIGN                                                   !6, <false>
   23    39      > JMPZ_EX                                          ~28     !4, ->41
         40    >   BOOL                                             ~28     !5
         41    > > JMPZ_EX                                          ~28     ~28, ->44
         42    >   BOOL_NOT                                         ~29     !6
         43        BOOL                                             ~28     ~29
         44    > > JMPZ                                                     ~28, ->48
   24    45    >   BW_OR                                            ~30     !3, 1.84467e+19
         46        ASSIGN                                                   !3, ~30
         47      > JMP                                                      ->60
   25    48    > > JMPZ_EX                                          ~32     !4, ->51
         49    >   BOOL_NOT                                         ~33     !5
         50        BOOL                                             ~32     ~33
         51    > > JMPZ_EX                                          ~32     ~32, ->53
         52    >   BOOL                                             ~32     !6
         53    > > JMPZ                                                     ~32, ->60
   26    54    >   BW_AND                                           ~34     !3, 2147483647
         55        MUL                                              ~35     ~34, 2
         56        BW_NOT                                           ~36     !3
         57        ADD                                              ~37     ~35, ~36
         58        ADD                                              ~38     ~37, 1
         59        ASSIGN                                                   !3, ~38
   29    60    > > RETURN                                                   !3
   30    61*     > RETURN                                                   null

End of function unpack_int32

Function unpack_int64:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 60
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 60
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
Branch analysis from position: 60
Branch analysis from position: 24
Branch analysis from position: 16
filename:       /in/ZfDP3
function name:  unpack_int64
number of ops:  62
compiled vars:  !0 = $str, !1 = $flags, !2 = $length, !3 = $is32bit, !4 = $longs, !5 = $signBit, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
   33     2        STRLEN                                           ~7      !0
          3        ASSIGN                                                   !2, ~7
   34     4        IS_SMALLER                                               !2, 8
          5      > JMPZ                                                     ~9, ->8
   35     6    > > RETURN                                                   <false>
          7*       JMP                                                      ->16
   36     8    >   IS_SMALLER                                               8, !2
          9      > JMPZ                                                     ~10, ->16
   37    10    >   INIT_FCALL                                               'substr'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 8
         14        DO_ICALL                                         $11     
         15        ASSIGN                                                   !0, $11
   40    16    >   ASSIGN                                                   !3, <false>
   42    17        FETCH_CONSTANT                                   ~14     'INT_LE'
         18        BW_AND                                           ~15     !1, ~14
         19      > JMPZ                                                     ~15, ->24
   43    20    >   INIT_FCALL                                               'strrev'
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                         $16     
         23        ASSIGN                                                   !0, $16
   45    24    >   INIT_FCALL                                               'array_values'
         25        INIT_FCALL                                               'unpack'
         26        SEND_VAL                                                 'NN'
         27        INIT_FCALL                                               'substr'
         28        SEND_VAR                                                 !0
         29        SEND_VAL                                                 0
         30        SEND_VAL                                                 4
         31        DO_ICALL                                         $18     
         32        SEND_VAR                                                 $18
         33        INIT_FCALL                                               'substr'
         34        SEND_VAR                                                 !0
         35        SEND_VAL                                                 4
         36        SEND_VAL                                                 4
         37        DO_ICALL                                         $19     
         38        SEND_VAR                                                 $19
         39        DO_ICALL                                         $20     
         40        SEND_VAR                                                 $20
         41        DO_ICALL                                         $21     
         42        ASSIGN                                                   !4, $21
   47    43        FETCH_DIM_R                                      ~23     !4, 0
         44        BW_AND                                           ~24     ~23, 2147483648
         45        BOOL                                             ~25     ~24
         46        ASSIGN                                                   !5, ~25
   49    47      > JMPZ                                                     <true>, ->60
   50    48    >   FETCH_DIM_R                                      ~27     !4, 0
         49        SL                                               ~28     ~27, 32
         50        FETCH_DIM_R                                      ~29     !4, 1
         51        BW_OR                                            ~30     ~28, ~29
         52        ASSIGN                                                   !6, ~30
   51    53      > JMPZ                                                     !5, ->60
   52    54    >   BW_AND                                           ~32     !6, 9223372036854775807
         55        MUL                                              ~33     ~32, 2
         56        BW_NOT                                           ~34     !6
         57        ADD                                              ~35     ~33, ~34
         58        ADD                                              ~36     ~35, 1
         59        ASSIGN                                                   !6, ~36
   56    60    > > RETURN                                                   !6
   57    61*     > RETURN                                                   null

End of function unpack_int64

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
196.15 ms | 1411 KiB | 28 Q