make casts more strict in PHP 7

From: Date: Tue, 09 Sep 2014 19:26:07 +0000
Subject: make casts more strict in PHP 7
Groups: php.internals 
Request: Send a blank email to internals+get-77117@lists.php.net to get a copy of this message
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

« previous php.internals (#77117) next »