> -----Original Message----- > From: Andrea Faulds [mailto:a...@ajf.me] > Sent: Sunday, July 13, 2014 6:19 PM > To: Zeev Suraski > Cc: Jocelyn Fournier; PHP internals > Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) > > 1. Casting type hints > 2. Strict type hints > 3. Scalar type hinting with casts > > (There are others, but I won't talk about them) > > I'm not of the opinion that the first option, where we just cast and never > error, is ideal. It does ensure the values are of the correct type when they get > to you, so it keeps PHP's type juggling, but it is unlikely to catch bugs where > the wrong value has been passed.
Let's stop for a moment right here. If we emit notices, or even new E_CAST, do we not get the exact same ability to catch errors you'd get from E_RECOVERABLE_ERROR? Even reading Nikita's piece, he's saying he dislikes that option for 'obvious reasons', but I see nothing obviously wrong with this approach. In fact, it gives you the full power of ensuring the correct types in the 'inner code', allows you to catch 'bad conversions' if you wish to (many don't, but I agree some and perhaps many would), and allows you to use this feature in the most widespread way possible while minimizing the amount of code you need to write in order to use it (no inflation in necessary try/catch blocks). Unlike what's suggested in that piece, it's not equivalent at all to docblocks, as it is in fact enforced, and as you said, has the benefit of being able to write the 'inner code' without worrying about the input types. Whether we go for option #1 or #3 doesn't change the amount of bugs you can find *if you wish to, unless I'm missing something. Option #3 forces you to explicitly deal with 'error' situations (which may or may not be errors), while option #1 leaves it up to the developer whether he wants to write 'E_CAST clean' code or not, similarly to E_STRICT (assuming we introduce E_CAST, we can choose an existing error level too). Zeev -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php