Using binary/bits for a permissions system, for one method (switchPermission - if it's 'on', change to 'off' and vice versa..) is the below (bar any optimisations) correct? My maths is poor and I haven't used bitwise for very long
Code: Select all
public function switchPermission ($perm)
{
if (!$this->perms & $perm) {
$this->perms += $perm;
} else {
$this->perms -= $perm;
}
}Code: Select all
$this->perms = ($this->perms ^ $perm);Thanks in advance