Well for starters it's a challenge to see if anyone can devise an interesting solution to the problem using only bitwise operators in a single statement - logicals too I guess.
I don't want to use conditional statements or ternary operators, etc....thats the challenege
The point is, I have several functions which are passed flags and sometimes flags are mutually exclusive, in that only one flag may be set, if more than one are set, the result is unexpected.
Having a simple, fast bitwise statement which could tell me TRUE or FALSE could be used inside the function to indicate argument error, by simply returning FALSE or some other value.
Unit testing the interface only doesn't suffice, because flags are coming from anywhere and everywhere and many conditions dictate whether one flag is set or not.
You could I guess write countless tests to see if any combination broke the test, but I think it would be easier to handle this on the implementation side of things seeing how there are a few functions which take STATES. Also there is the added benefit that production time slip ups are also flagged, not just while unit testing.
I have always used an implementation test (using macros which disappear in release) strategy so it's natural for me to continue to do so.
In PHP it's not very efficient to load your code with implementation level checks as PHP doesn't have a preprocessor so unit testing in environments like this comes in handy, but we still shouldn't neglect implementation level testing, just try and make it as transparent as possible and as fast as possible - hence a single bitwise statement which could quickly do the trick
Cheers
