3v4l.org

run code in 300+ PHP versions simultaneously
<?php const READ = 0b001; const WRITE = 0b010; const EXECUTE = 0b100; function testBit($flags, $bit) { return !! ($flags & $bit); } function clearBit($flags, $bit) { return $flags ^ $bit; } function setBit($flags, $bit) { return $flags | $bit; } function toggleBit($flags, $bit) { return $flags ^ $bit; } $guest = READ; $user = READ | WRITE; $admin = READ | WRITE | EXECUTE; assert(!testBit($guest, WRITE)); assert(testBit(setBit($guest, WRITE), WRITE)); assert(testBit($user, WRITE)); assert(!testBit(clearBit($user, WRITE), WRITE)); $admin = toggleBit($admin, EXECUTE); assert(!testBit($admin, EXECUTE)); $admin = toggleBit($admin, EXECUTE); assert(testBit($admin, EXECUTE));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GNWKP
function name:  (null)
number of ops:  101
compiled vars:  !0 = $guest, !1 = $user, !2 = $admin
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                            'READ', 1
    4     1        DECLARE_CONST                                            'WRITE', 2
    5     2        DECLARE_CONST                                            'EXECUTE', 4
   23     3        FETCH_CONSTANT                                   ~3      'READ'
          4        ASSIGN                                                   !0, ~3
   24     5        FETCH_CONSTANT                                   ~5      'READ'
          6        FETCH_CONSTANT                                   ~6      'WRITE'
          7        BW_OR                                            ~7      ~5, ~6
          8        ASSIGN                                                   !1, ~7
   25     9        FETCH_CONSTANT                                   ~9      'READ'
         10        FETCH_CONSTANT                                   ~10     'WRITE'
         11        BW_OR                                            ~11     ~9, ~10
         12        FETCH_CONSTANT                                   ~12     'EXECUTE'
         13        BW_OR                                            ~13     ~11, ~12
         14        ASSIGN                                                   !2, ~13
   27    15        ASSERT_CHECK                                             
         16        INIT_FCALL                                               'assert'
         17        INIT_FCALL                                               'testbit'
         18        SEND_VAR                                                 !0
         19        FETCH_CONSTANT                                   ~15     'WRITE'
         20        SEND_VAL                                                 ~15
         21        DO_FCALL                                      0  $16     
         22        BOOL_NOT                                         ~17     $16
         23        SEND_VAL                                                 ~17
         24        SEND_VAL                                                 'assert%28%21testBit%28%24guest%2C+WRITE%29%29'
         25        DO_ICALL                                                 
   28    26        ASSERT_CHECK                                             
         27        INIT_FCALL                                               'assert'
         28        INIT_FCALL                                               'testbit'
         29        INIT_FCALL                                               'setbit'
         30        SEND_VAR                                                 !0
         31        FETCH_CONSTANT                                   ~19     'WRITE'
         32        SEND_VAL                                                 ~19
         33        DO_FCALL                                      0  $20     
         34        SEND_VAR                                                 $20
         35        FETCH_CONSTANT                                   ~21     'WRITE'
         36        SEND_VAL                                                 ~21
         37        DO_FCALL                                      0  $22     
         38        SEND_VAR                                                 $22
         39        SEND_VAL                                                 'assert%28testBit%28setBit%28%24guest%2C+WRITE%29%2C+WRITE%29%29'
         40        DO_ICALL                                                 
   30    41        ASSERT_CHECK                                             
         42        INIT_FCALL                                               'assert'
         43        INIT_FCALL                                               'testbit'
         44        SEND_VAR                                                 !1
         45        FETCH_CONSTANT                                   ~24     'WRITE'
         46        SEND_VAL                                                 ~24
         47        DO_FCALL                                      0  $25     
         48        SEND_VAR                                                 $25
         49        SEND_VAL                                                 'assert%28testBit%28%24user%2C+WRITE%29%29'
         50        DO_ICALL                                                 
   31    51        ASSERT_CHECK                                             
         52        INIT_FCALL                                               'assert'
         53        INIT_FCALL                                               'testbit'
         54        INIT_FCALL                                               'clearbit'
         55        SEND_VAR                                                 !1
         56        FETCH_CONSTANT                                   ~27     'WRITE'
         57        SEND_VAL                                                 ~27
         58        DO_FCALL                                      0  $28     
         59        SEND_VAR                                                 $28
         60        FETCH_CONSTANT                                   ~29     'WRITE'
         61        SEND_VAL                                                 ~29
         62        DO_FCALL                                      0  $30     
         63        BOOL_NOT                                         ~31     $30
         64        SEND_VAL                                                 ~31
         65        SEND_VAL                                                 'assert%28%21testBit%28clearBit%28%24user%2C+WRITE%29%2C+WRITE%29%29'
         66        DO_ICALL                                                 
   33    67        INIT_FCALL                                               'togglebit'
         68        SEND_VAR                                                 !2
         69        FETCH_CONSTANT                                   ~33     'EXECUTE'
         70        SEND_VAL                                                 ~33
         71        DO_FCALL                                      0  $34     
         72        ASSIGN                                                   !2, $34
   34    73        ASSERT_CHECK                                             
         74        INIT_FCALL                                               'assert'
         75        INIT_FCALL                                               'testbit'
         76        SEND_VAR                                                 !2
         77        FETCH_CONSTANT                                   ~36     'EXECUTE'
         78        SEND_VAL                                                 ~36
         79        DO_FCALL                                      0  $37     
         80        BOOL_NOT                                         ~38     $37
         81        SEND_VAL                                                 ~38
         82        SEND_VAL                                                 'assert%28%21testBit%28%24admin%2C+EXECUTE%29%29'
         83        DO_ICALL                                                 
   35    84        INIT_FCALL                                               'togglebit'
         85        SEND_VAR                                                 !2
         86        FETCH_CONSTANT                                   ~40     'EXECUTE'
         87        SEND_VAL                                                 ~40
         88        DO_FCALL                                      0  $41     
         89        ASSIGN                                                   !2, $41
   36    90        ASSERT_CHECK                                             
         91        INIT_FCALL                                               'assert'
         92        INIT_FCALL                                               'testbit'
         93        SEND_VAR                                                 !2
         94        FETCH_CONSTANT                                   ~43     'EXECUTE'
         95        SEND_VAL                                                 ~43
         96        DO_FCALL                                      0  $44     
         97        SEND_VAR                                                 $44
         98        SEND_VAL                                                 'assert%28testBit%28%24admin%2C+EXECUTE%29%29'
         99        DO_ICALL                                                 
        100      > RETURN                                                   1

Function testbit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GNWKP
function name:  testBit
number of ops:  7
compiled vars:  !0 = $flags, !1 = $bit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        BW_AND                                           ~2      !0, !1
          3        BOOL_NOT                                         ~3      ~2
          4        BOOL_NOT                                         ~4      ~3
          5      > RETURN                                                   ~4
    9     6*     > RETURN                                                   null

End of function testbit

Function clearbit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GNWKP
function name:  clearBit
number of ops:  5
compiled vars:  !0 = $flags, !1 = $bit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        BW_XOR                                           ~2      !0, !1
          3      > RETURN                                                   ~2
   13     4*     > RETURN                                                   null

End of function clearbit

Function setbit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GNWKP
function name:  setBit
number of ops:  5
compiled vars:  !0 = $flags, !1 = $bit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        BW_OR                                            ~2      !0, !1
          3      > RETURN                                                   ~2
   17     4*     > RETURN                                                   null

End of function setbit

Function togglebit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GNWKP
function name:  toggleBit
number of ops:  5
compiled vars:  !0 = $flags, !1 = $bit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   20     2        BW_XOR                                           ~2      !0, !1
          3      > RETURN                                                   ~2
   21     4*     > RETURN                                                   null

End of function togglebit

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.81 ms | 1411 KiB | 25 Q