3v4l.org

run code in 300+ PHP versions simultaneously
<?php const INT_SIGNED = 1; const INT_LE = 2; function isLittleEndian() { return pack('S', 0x00FF) === "\xFF\x00"; } function is32Bit() { return PHP_INT_MAX < 0x80000000; } function unpack_int32($str, $flags = 0) { $length = strlen($str); if ($length < 4) { return false; } else if ($length > 4) { $str = substr($str, 0, 4); } $format = ($flags & INT_LE) ? 'V' : 'N'; $result = current(unpack($format, $str)); if (($result & 0x80000000) && ($flags & INT_SIGNED) && !is32Bit()) { $result = 0xFFFFFFFF00000000 | $result; } return $result; } var_dump(isLittleEndian(), is32Bit(), unpack_int32("\xFF\xFF\xFF\xFE", INT_SIGNED));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/g4s7Y
function name:  (null)
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                            'INT_SIGNED', 1
    4     1        DECLARE_CONST                                            'INT_LE', 2
   31     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'islittleendian'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        INIT_FCALL                                               'is32bit'
          7        DO_FCALL                                      0  $1      
          8        SEND_VAR                                                 $1
          9        INIT_FCALL                                               'unpack_int32'
         10        SEND_VAL                                                 '%FF%FF%FF%FE'
         11        FETCH_CONSTANT                                   ~2      'INT_SIGNED'
         12        SEND_VAL                                                 ~2
         13        DO_FCALL                                      0  $3      
         14        SEND_VAR                                                 $3
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Function islittleendian:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/g4s7Y
function name:  isLittleEndian
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   INIT_FCALL                                               'pack'
          1        SEND_VAL                                                 'S'
          2        SEND_VAL                                                 255
          3        DO_ICALL                                         $0      
          4        IS_IDENTICAL                                     ~1      $0, '%FF%00'
          5      > RETURN                                                   ~1
    8     6*     > RETURN                                                   null

End of function islittleendian

Function is32bit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/g4s7Y
function name:  is32Bit
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E > > RETURN                                                   <false>
   11     1*     > RETURN                                                   null

End of function is32bit

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 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
2 jumps found. (Code = 46) Position 1 = 37, Position 2 = 41
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 41
Branch analysis from position: 36
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
Branch analysis from position: 36
Branch analysis from position: 16
filename:       /in/g4s7Y
function name:  unpack_int32
number of ops:  46
compiled vars:  !0 = $str, !1 = $flags, !2 = $length, !3 = $format, !4 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
   14     2        STRLEN                                           ~5      !0
          3        ASSIGN                                                   !2, ~5
   15     4        IS_SMALLER                                               !2, 4
          5      > JMPZ                                                     ~7, ->8
   16     6    > > RETURN                                                   <false>
          7*       JMP                                                      ->16
   17     8    >   IS_SMALLER                                               4, !2
          9      > JMPZ                                                     ~8, ->16
   18    10    >   INIT_FCALL                                               'substr'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 4
         14        DO_ICALL                                         $9      
         15        ASSIGN                                                   !0, $9
   21    16    >   FETCH_CONSTANT                                   ~11     'INT_LE'
         17        BW_AND                                           ~12     !1, ~11
         18      > JMPZ                                                     ~12, ->21
         19    >   QM_ASSIGN                                        ~13     'V'
         20      > JMP                                                      ->22
         21    >   QM_ASSIGN                                        ~13     'N'
         22    >   ASSIGN                                                   !3, ~13
   22    23        INIT_FCALL                                               'current'
         24        INIT_FCALL                                               'unpack'
         25        SEND_VAR                                                 !3
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $15     
         28        SEND_VAR                                                 $15
         29        DO_ICALL                                         $16     
         30        ASSIGN                                                   !4, $16
   24    31        BW_AND                                           ~18     !4, 2147483648
         32      > JMPZ_EX                                          ~18     ~18, ->36
         33    >   FETCH_CONSTANT                                   ~19     'INT_SIGNED'
         34        BW_AND                                           ~20     !1, ~19
         35        BOOL                                             ~18     ~20
         36    > > JMPZ_EX                                          ~18     ~18, ->41
         37    >   INIT_FCALL                                               'is32bit'
         38        DO_FCALL                                      0  $21     
         39        BOOL_NOT                                         ~22     $21
         40        BOOL                                             ~18     ~22
         41    > > JMPZ                                                     ~18, ->44
   25    42    >   BW_OR                                            ~23     !4, 1.84467e+19
         43        ASSIGN                                                   !4, ~23
   28    44    > > RETURN                                                   !4
   29    45*     > RETURN                                                   null

End of function unpack_int32

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.24 ms | 1407 KiB | 27 Q