Why should I use bitwise/bitmask in PHP?

后端 未结 8 1939
时光取名叫无心
时光取名叫无心 2020-11-30 20:54

I am working on a user-role / permission system in PHP for a script.

Below is a code using a bitmask method for permissions that I found on phpbuilder.com.

B

8条回答
  •  盖世英雄少女心
    2020-11-30 21:27

    I guess the first example gives you more control of exactly what permissions a user has. In the second you just have a user 'level'; presumably higher levels inherit all the permissions granted to a lower 'level' user, so you don't have such fine control.

    Also, if I have understood correctly, the line

    if($user_permission_level === 4)
    

    means that only users with exactly permission level 4 have access to the action - surely you would want to check that users have at least that level?

提交回复
热议问题