3v4l.org

run code in 300+ PHP versions simultaneously
<?php # BitwiseFlag.php abstract class BitwiseFlag { protected $flags; /* * Note: these functions are protected to prevent outside code * from falsely setting BITS. See how the extending class 'User' * handles this. * */ protected function isFlagSet($flag) { return (($this->flags & $flag) == $flag); } protected function setFlag($flag, $value) { if($value) { $this->flags |= $flag; } else { $this->flags &= ~$flag; } } } class User extends BitwiseFlag { const FLAG_REGISTERED = 1; // BIT #1 of $flags has the value 1 const FLAG_ACTIVE = 2; // BIT #2 of $flags has the value 2 const FLAG_MEMBER = 4; // BIT #3 of $flags has the value 4 const FLAG_ADMIN = 8; // BIT #4 of $flags has the value 8 public function isRegistered(){ return $this->isFlagSet(self::FLAG_REGISTERED); } public function isActive(){ return $this->isFlagSet(self::FLAG_ACTIVE); } public function isMember(){ return $this->isFlagSet(self::FLAG_MEMBER); } public function isAdmin(){ return $this->isFlagSet(self::FLAG_ADMIN); } public function setRegistered($value){ $this->setFlag(self::FLAG_REGISTERED, $value); } public function setActive($value){ $this->setFlag(self::FLAG_ACTIVE, $value); } public function setMember($value){ $this->setFlag(self::FLAG_MEMBER, $value); } public function setAdmin($value){ $this->setFlag(self::FLAG_ADMIN, $value); } public function __toString(){ return 'User [' . ($this->isRegistered() ? 'REGISTERED' : '') . ($this->isActive() ? ' ACTIVE' : '') . ($this->isMember() ? ' MEMBER' : '') . ($this->isAdmin() ? ' ADMIN' : '') . ']'; } } $user = new User(); $user->setRegistered(true); $user->setActive(true); $user->setMember(true); $user->setAdmin(true); echo $user; // outputs: User [REGISTERED ACTIVE MEMBER ADMIN]
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fshjV
function name:  (null)
number of ops:  18
compiled vars:  !0 = $user
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   DECLARE_CLASS                                            'user', 'bitwiseflag'
   84     1        NEW                                              $1      'User'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   85     4        INIT_METHOD_CALL                                         !0, 'setRegistered'
          5        SEND_VAL_EX                                              <true>
          6        DO_FCALL                                      0          
   86     7        INIT_METHOD_CALL                                         !0, 'setActive'
          8        SEND_VAL_EX                                              <true>
          9        DO_FCALL                                      0          
   87    10        INIT_METHOD_CALL                                         !0, 'setMember'
         11        SEND_VAL_EX                                              <true>
         12        DO_FCALL                                      0          
   88    13        INIT_METHOD_CALL                                         !0, 'setAdmin'
         14        SEND_VAL_EX                                              <true>
         15        DO_FCALL                                      0          
   90    16        ECHO                                                     !0
         17      > RETURN                                                   1

Class BitwiseFlag:
Function isflagset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fshjV
function name:  isFlagSet
number of ops:  6
compiled vars:  !0 = $flag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        FETCH_OBJ_R                                      ~1      'flags'
          2        BW_AND                                           ~2      !0, ~1
          3        IS_EQUAL                                         ~3      !0, ~2
          4      > RETURN                                                   ~3
   18     5*     > RETURN                                                   null

End of function isflagset

Function setflag:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fshjV
function name:  setFlag
number of ops:  10
compiled vars:  !0 = $flag, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2      > JMPZ                                                     !1, ->6
   24     3    >   ASSIGN_OBJ_OP                                 9          'flags'
          4        OP_DATA                                                  !0
          5      > JMP                                                      ->9
   28     6    >   BW_NOT                                           ~4      !0
          7        ASSIGN_OBJ_OP                                10          'flags'
          8        OP_DATA                                                  ~4
   30     9    > > RETURN                                                   null

End of function setflag

End of class BitwiseFlag.

Class User:
Function isregistered:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fshjV
function name:  isRegistered
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   INIT_METHOD_CALL                                         'isFlagSet'
          1        SEND_VAL_EX                                              1
          2        DO_FCALL                                      0  $0      
          3      > RETURN                                                   $0
   43     4*     > RETURN                                                   null

End of function isregistered

Function isactive:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fshjV
function name:  isActive
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   INIT_METHOD_CALL                                         'isFlagSet'
          1        SEND_VAL_EX                                              2
          2        DO_FCALL                                      0  $0      
          3      > RETURN                                                   $0
   47     4*     > RETURN                                                   null

End of function isactive

Function ismember:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fshjV
function name:  isMember
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   INIT_METHOD_CALL                                         'isFlagSet'
          1        SEND_VAL_EX                                              4
          2        DO_FCALL                                      0  $0      
          3      > RETURN                                                   $0
   51     4*     > RETURN                                                   null

End of function ismember

Function isadmin:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fshjV
function name:  isAdmin
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   INIT_METHOD_CALL                                         'isFlagSet'
          1        SEND_VAL_EX                                              8
          2        DO_FCALL                                      0  $0      
          3      > RETURN                                                   $0
   55     4*     > RETURN                                                   null

End of function isadmin

Function setregistered:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fshjV
function name:  setRegistered
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   RECV                                             !0      
   58     1        INIT_METHOD_CALL                                         'setFlag'
          2        SEND_VAL_EX                                              1
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   59     5      > RETURN                                                   null

End of function setregistered

Function setactive:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fshjV
function name:  setActive
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   RECV                                             !0      
   62     1        INIT_METHOD_CALL                                         'setFlag'
          2        SEND_VAL_EX                                              2
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   63     5      > RETURN                                                   null

End of function setactive

Function setmember:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fshjV
function name:  setMember
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
   66     1        INIT_METHOD_CALL                                         'setFlag'
          2        SEND_VAL_EX                                              4
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   67     5      > RETURN                                                   null

End of function setmember

Function setadmin:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fshjV
function name:  setAdmin
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
   70     1        INIT_METHOD_CALL                                         'setFlag'
          2        SEND_VAL_EX                                              8
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   71     5      > RETURN                                                   null

End of function setadmin

Function __tostring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
Branch analysis from position: 26
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
Branch analysis from position: 19
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
Branch analysis from position: 12
filename:       /in/fshjV
function name:  __toString
number of ops:  33
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   75     0  E >   INIT_METHOD_CALL                                         'isRegistered'
          1        DO_FCALL                                      0  $0      
          2      > JMPZ                                                     $0, ->5
          3    >   QM_ASSIGN                                        ~1      'REGISTERED'
          4      > JMP                                                      ->6
          5    >   QM_ASSIGN                                        ~1      ''
          6    >   CONCAT                                           ~2      'User+%5B', ~1
   76     7        INIT_METHOD_CALL                                         'isActive'
          8        DO_FCALL                                      0  $3      
          9      > JMPZ                                                     $3, ->12
         10    >   QM_ASSIGN                                        ~4      '+ACTIVE'
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~4      ''
         13    >   CONCAT                                           ~5      ~2, ~4
   77    14        INIT_METHOD_CALL                                         'isMember'
         15        DO_FCALL                                      0  $6      
         16      > JMPZ                                                     $6, ->19
         17    >   QM_ASSIGN                                        ~7      '+MEMBER'
         18      > JMP                                                      ->20
         19    >   QM_ASSIGN                                        ~7      ''
         20    >   CONCAT                                           ~8      ~5, ~7
   78    21        INIT_METHOD_CALL                                         'isAdmin'
         22        DO_FCALL                                      0  $9      
         23      > JMPZ                                                     $9, ->26
         24    >   QM_ASSIGN                                        ~10     '+ADMIN'
         25      > JMP                                                      ->27
         26    >   QM_ASSIGN                                        ~10     ''
         27    >   CONCAT                                           ~11     ~8, ~10
   79    28        CONCAT                                           ~12     ~11, '%5D'
         29        VERIFY_RETURN_TYPE                                       ~12
         30      > RETURN                                                   ~12
   80    31*       VERIFY_RETURN_TYPE                                       
         32*     > RETURN                                                   null

End of function __tostring

End of class User.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.48 ms | 1398 KiB | 13 Q