How can you identify that the integer given (the sum of potential flags) consists of the predefined flags...?
Maybe that way:
<?php
define('IS_NEW', 0);
define('IS_PAID', 2);
define('IS_EXTEND', 4);
define('IS_TRACK', 8);
define('IS_VIP', 16);
define('IS_HOT', 32);
define('IS_BLOCKED', 64);
class myConsts {
public $constants = ['IS_NEW','IS_PAID', 'IS_EXTEND', 'IS_TRACK', 'IS_VIP', 'IS_HOT', 'IS_BLOCKED'];
function __construct() {
foreach ($this->constants as &$cons) {
$cons = -constant($cons) -1; // negation, f.e. 0b...00000001 ==> 0b...11111110 (32 or 64 bits depends of platform)
//printf("0b%08b.\n", $cons); // (test)
}
}
function checkInt($myInt = 0) {
foreach ($this->constants as $cons) {
$myInt = $myInt & $cons;
}
return $myInt;
}
}
$checkInts = new myConsts();
foreach ([48, 50, 75, 256*200+156] as $getInt) {
$result = $checkInts->checkInt($getInt);
if ($result) {
echo "Int ".sprintf("%u (0b%1$08b)", $getInt)." constains more flags: ", sprintf("0b%08b.", $result), PHP_EOL;
} else {
echo "Int ".sprintf("%u (0b%1$08b)", $getInt)." consists only of predefined flags!", PHP_EOL;
}
}
?>
Result:
Int 48 (0b00110000) consists only of predefined flags!
Int 50 (0b00110010) consists only of predefined flags!
Int 75 (0b01001011) constains more flags: 0b00000001.
Int 51356 (0b1100100010011100) constains more flags: 0b1100100010000000.
Is this what you need?