You can do that in several ways. You might store an integer property associated with the user, then define the flags as integer powers of 2:
define('CAN_CREATE_THREAD', 0x0010);
define('CAN_DELETE_THREAD', 0x0020);
then to your hasFlag($flag)
could be something like
return ($this->BinaryFlags & $flag);
Otherwise you can store all the flags in the database:
CREATE TABLE flags
(
id integer not null primary key auto_increment,
name varchar(32)
);
CREATE TABLE has_flag
(
user_id integer,
flag_id integer
);
and your hasFlag function is a query to the database.
Role-level access is the same, except that you do not store flags associating them to an user, but rather associate an user to a role (so you have a table like (user_id, role_id)
), and then associate the flags to the role as shown above.
The advantage is that you can define a person as "Section XYZ Administrator" without having to remember and set all permissions one by one; the disadvantage is that you can't have intermediate states (say, a semi-administrator that can edit but not create) unless you create the role first.