Hi!
According to Zeev's description of the behavior this would cause a fatal error, as $_GET['a'] cannot be converted to an integer value.. I like that, but I think we need to devise a mechanism that allows you to catch this error at runtime and write application logic around it... In the simple case above the point would be to be able to catch
Well, we could make it E_RECOVERABLE_ERROR. But it's not customizable, unfortunately. If you want graceful handling (like custom error messages), I don't believe you can do it language-level. Use app-level validators (like Zend_Validate in Zend Framework) for that.
the error so that the requesting user could be informed he must enter two integer values. Off the top of my head the only mechanism that I can think of would be to throw an exception, which I'm not crazy about either: try { print foo($_GET['a'], $_GET['b']); } catch(TypeCheckException $e) { print "Sorry, you need to provide two integer values!"; }
If you're going to write specific code to catch specific exceptions, why don't you just check for specific constraints? It's the same amount of code, but done the right way - you say what you actually mean to do and do not make validation an afterthought, and allows you to give the user much better feedback ("this field is wrong" instead of "some field is wrong"). And what happens to your code after you add one more value? I think app-level validation mechanism would work much better in this case.
Personally I really like the practical feel and ease of understanding of using an exception in this case, but the idea of an exception being thrown from potentially procedural code isn't the best thing to me..
I think exception would be impractical in real user-facing code - it's too generic to give useful information, and you will have to have validation on top of that anyway (emails, html, whatever).
-- Stanislav Malyshev, Zend Software Architect s...@zend.com http://www.zend.com/ (408)253-8829 MSN: s...@zend.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php