laserlight wrote:No, since the setter failed (i.e., the member variable still contains the "previous" value), the member variable would not have an invalid value. This is not what the client wants, but the member function's contract is that it was the client's responsibility to check the return value or otherwise guarantee that the setter succeeded.
Yes, I ignored my code logic. 🙂 In my example, if an invalid input is given then the current value will remain unchanged. At that point I can do as you suggest and return FALSE, and then say it's the client program's fault if it does not check the result and instead continues merrily along its way assuming that the change has been made. Or I can say that my end of the "contract" is to throw an exception, and it's the client's responsibility to catch any such exception. But, if it ignores the contract, then at least it will get an uncaught exception if an invalid value is given and it will be immediately obvious something is wrong. The counter-argument is that this might be overkill and could result in information being displayed in error messages that could be a security issue. But then, a production system should not be displaying errors, right?
So I guess it sort of comes down to how much responsibility you want to delegate to the client program versus assuming it may be sloppy and taking the responsibility myself to ensure proper "contract compliance." Therefore I'm sort of leaning toward using exceptions for such things right now, but that might simply be because currently they are a new PHP "toy" for me that I've really just started "playing" with. 🙂