Heya,

I remember that some people were complaining about the inconsistencies
between normal conversions and the one applied in Andrea's RFC about "Scalar
Type Hinting With Casts". 
https://wiki.php.net/rfc/scalar_type_hinting_with_cast

As an example:

$i = (int) "a"; //fine without errors
function foo(int $i){}
foo("a"); //E_RECOVERABLE_ERROR

Personally, I do not like such inconsistencies either but I like that the
conversion rules in Andrea's RFC are more strict. And thus I was asking
myself if it would not make sense to change the current behaviour of
castings and make them more strict in PHP 7.
In the same time we could introduce a cast operator as the "as" operator in
C# which would have the current behaviour.
I believe that we would make PHP applications more robust in this way. At
least I doubt that the majority wants to convert "a" to 0. IMO most people
would prefer that PHP bails out an error in such a case. Sure one could also
write if's and check first if it is numeric etc. but that should be easier
IMO.

Just as an idea. What do you think?

Cheers,
Robert




-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to