Oihana PHP

isValidMask.php

Table of Contents

Functions

isValidMask()  : bool
Validates that a bitmask contains only allowed flags.

Functions

isValidMask()

Validates that a bitmask contains only allowed flags.

isValidMask(int $mask, int $allowed) : bool
Parameters
$mask : int

The bitmask to validate.

$allowed : int

A bitmask of all valid flags.

Tags
example
use function oihana\core\bits\isValidMask;

const FLAG_A = 1 << 0; // 1
const FLAG_B = 1 << 1; // 2
const FLAG_C = 1 << 2; // 4
const ALL_FLAGS = FLAG_A | FLAG_B | FLAG_C; // 7

$mask = FLAG_A | FLAG_B;
isValidMask( $mask , ALL_FLAGS ) ; // true

$mask = FLAG_A | FLAG_B | (1 << 5);
isValidMask( $mask , ALL_FLAGS ) ; // false, bit 5 is invalid
author

Marc Alcaraz (ekameleon)

since
1.0.7
Return values
bool

Returns true if all bits in $mask are present in $allowed, false otherwise.


        
On this page

Search results