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]
Output for 5.0.0 - 5.0.5, 5.1.1 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
User [REGISTERED ACTIVE MEMBER ADMIN]
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/fshjV on line 90
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CLASS in /in/fshjV on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_CLASS in /in/fshjV on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/fshjV on line 5
Process exited with code 255.

preferences:
278.26 ms | 401 KiB | 449 Q