- var_dump: documentation ( source)
- in_array: documentation ( source)
<?php
class MyBitmask {
const POS_1 = 1;
// const POS_2 = 2; // reserved/undefined
// const POS_3 = 3; // reserved/undefined
const POS_4 = 4;
private $b = 0x0000;
function setChecked($pos) {
if (in_array($pos, (new ReflectionClass($this))->getConstants())) {
$this->set($pos);
}
return $this;
}
function set($pos) {
$this->b |= 1 << ($pos - 1);
return $this;
}
}
$b = new MyBitmask();
var_dump($b->setChecked(2));
var_dump($b->set(2));