waikay.net

rambles of an avid procrastinator
"Why do today what you can do tomorrow?"

Archive for January 25th, 2006

Pop Quiz

Wednesday, 25 January 2006, 6:08 pm, me

Here’s a pop quiz for all you l33t c0d3rz out there, so if you’re not one then this post is not for you.

I was modding a component for a web application written in PHP and came upon this little problem. The application stores user access levels not in an enumerated type but as a plain string say $usertype. The user levels are in fact supposed to be enumerated say 5 levels: “Administrator”, “Manager”, “Editor”, “Registered”, “Anonymous”, where of course privileges of the higher level would encompass the lower ones.

Now I have to modify a function called has_priv($priv, $usertype) which takes in two strings and return true if the given $usertype does indeed have privileges under the given $priv and false otherwise.

For example, has_priv(’Editor’, ‘Manager’) will return true as Manager is above Editor, and has_priv(’Manager’, ‘Registered’) will return false.

Come up with a quick and easy way to implement such a function and post it in the comments. My purpose is to investigate how different people will solve this simple problem, and to find any cleaner solution than mine. I’ll be posting my solution after I gathered a few feedbacks.

This is coded in PHP but pseudo code with standard functions will suffice. Let’s see your l33t 5k!llz!!!

Filed under: jargon

Creative Commons License
Except stated otherwise, content of this site is
licensed under a Creative Commons License.