At 19:55 09/06/2010, Jared Williams wrote:
Is E_TYPE good enough? If it follows the other E_*, I'd suggest it's not.
Yes, same error mechanism.
Just having a single string error message describing the error, and having to unmangle the detailed information* from that doesn't seem that great.
The error here is not for the function to be able to 'recover' from that situation. The function will behave fine, since it'll still get what it expected to get (the value still gets converted to the required type). It's for the caller - indicating that wrong arguments were supplied.
I can't seem to understand why it makes sense to save on type conversion and/or validation code and invest in error recovery code instead. Cluttering the function with checks into which argument was supplied, what type it had and what it was converted to would be ugly and convoluted and negate the advantage of using type hints in the first place. If you want to have some complex type validation/recovery routines, then simply implement them - don't use type hints and then design the function to recover from situations you may consider as errors.
Zeev -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php