2015-10-27 179 views
0


我是新來的PHP和嘗試我的手從一個PHP登錄系統從this頁但有點混淆關於一段代碼。PHP用戶帳戶系統

下面顯示的代碼片段。

<?php 
 

 
class UserPermissions { 
 

 
\t const READ_POSTS = 1; 
 
\t const POST_NEW_THREADS = 2; 
 
\t const POST_NEW_REPLIES = 4; 
 
\t const EDIT_OWN_POSTS = 8; 
 
\t const EDIT_OTHERS_POSTS = 16; 
 
\t const DELETE_OWN_POSTS = 32; 
 
\t const DELETE_OTHERS_POSTS = 64; 
 
\t const MOVE_THREADS = 128; 
 
\t const SPLIT_THREADS = 256; 
 
\t const MERGE_THREADS = 512; 
 
\t const BAN_USERS = 1024; 
 
\t const WARN_USERS = 2048; 
 
\t const ACCESS_ADMIN_PANEL = 4096; 
 
\t // And so on and so on 
 
\t 
 
\t protected $perms; 
 
\t 
 
\t function __construct($permissions) { 
 
\t \t $this->perms = $permissions; 
 
\t } 
 
\t 
 
\t function hasPermission($perm) { 
 
\t \t return ($this->perms & $perm) === $perm; 
 
\t } 
 
} 
 

 
?>

主要焦點是hasPermision功能和返回值是如何計算的。

+2

這是一個比較明智的比較。閱讀位和運算符('&')。 –

回答