> Hi! > > > No, no it would not. PHP’s explicit casts cannot fail, and there is > > absolutely no good reason to change this. If people want strict > > casting, we can add new functions or operators for that specifically. > > But to break explicit casts and make them sometimes fail would cause > > innumerable bugs and backwards-compatibility ideas. > > I agree. If the developer explicitly states they want conversion, it > should be conversion. For implicit casts, some tightening may be ok, but > for explicit ones I think it would bring much more headaches than it's > worth. >
Precisely, it would cause a vast amount of headaches for many projects. Think of user input where you are expecting an integer and it must be a positive integer (which would ultimately be a string); it is much faster to do a quick check such as: $foo = (int) $_GET['foo']; if ($foo > 0) { .... } I'd personally not have to wrap more items around it due to a notice or warning.