Am new to php and trying my hands on a php login system from this page But am bit confuse about a piece of code.
Code snippet presented below.
<?php
class UserPermissions {
const READ_POSTS = 1;
const POST_NEW_THREADS = 2;
const POST_NEW_REPLIES = 4;
const EDIT_OWN_POSTS = 8;
const EDIT_OTHERS_POSTS = 16;
const DELETE_OWN_POSTS = 32;
const DELETE_OTHERS_POSTS = 64;
const MOVE_THREADS = 128;
const SPLIT_THREADS = 256;
const MERGE_THREADS = 512;
const BAN_USERS = 1024;
const WARN_USERS = 2048;
const ACCESS_ADMIN_PANEL = 4096;
// And so on and so on
protected $perms;
function __construct($permissions) {
$this->perms = $permissions;
}
function hasPermission($perm) {
return ($this->perms & $perm) === $perm;
}
}
?>
The main focus is the hasPermision function and how the return value is calculated.
</div>