3v4l.org

run code in 300+ PHP versions simultaneously
<?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));

preferences:
45.16 ms | 402 KiB | 5 Q