Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77117 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54331 invoked from network); 9 Sep 2014 19:26:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Sep 2014 19:26:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:52705] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1B/A4-08634-5545F045 for ; Tue, 09 Sep 2014 15:26:15 -0400 Received: (qmail 8199 invoked from network); 9 Sep 2014 21:26:09 +0200 Received: from cm56-129-238.liwest.at (HELO RoLaptop) (86.56.129.238) by ns73.kreativmedia.ch with (AES128-SHA encrypted) SMTP; 9 Sep 2014 21:26:09 +0200 To: Date: Tue, 9 Sep 2014 21:26:07 +0200 Message-ID: <004d01cfcc63$e7e3ac40$b7ab04c0$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: Ac/MY7ioZxn2SKKaRsCEKv8nTdK8bA== Content-Language: de-ch Subject: make casts more strict in PHP 7 From: php@tutteli.ch ("Robert Stoll") 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