Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83044 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79633 invoked from network); 18 Feb 2015 11:14:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 11:14:39 -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:39993] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F0/0A-18888-D1474E45 for ; Wed, 18 Feb 2015 06:14:38 -0500 Received: (qmail 13818 invoked from network); 18 Feb 2015 12:14:33 +0100 Received: from cm56-153-252.liwest.at (HELO RoLaptop) (86.56.153.252) by ns73.kreativmedia.ch with ESMTPSA (AES256-SHA encrypted, authenticated); 18 Feb 2015 12:14:33 +0100 To: "'Zeev Suraski'" , "'Nikita Popov'" , "'Rasmus Lerdorf'" Cc: "'Sara Golemon'" , "'PHP internals'" References: <54E3E27B.2010903@lerdorf.com> <2f99c47df51fa6c73131032ec50fade0@mail.gmail.com> In-Reply-To: <2f99c47df51fa6c73131032ec50fade0@mail.gmail.com> Date: Wed, 18 Feb 2015 12:14:29 +0100 Message-ID: <005201d04b6c$1122d130$33687390$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQKz6wpj8b81mnwJq1LfxWbU4ZJyQgGjcksIAbrU1N8Bn0wufQGLyLi6mvqvtiA= Content-Language: de-ch Subject: AW: [PHP-DEV] Scalar Type Hints v0.4 From: php@tutteli.ch ("Robert Stoll") > -----Urspr=C3=BCngliche Nachricht----- > Von: Zeev Suraski [mailto:zeev@zend.com] > Gesendet: Mittwoch, 18. Februar 2015 08:00 > An: Nikita Popov; Rasmus Lerdorf > Cc: Sara Golemon; PHP internals > Betreff: RE: [PHP-DEV] Scalar Type Hints v0.4 >=20 > > -----Original Message----- > > From: Nikita Popov [mailto:nikita.ppv@gmail.com] > > Sent: Wednesday, February 18, 2015 3:06 AM > > To: Rasmus Lerdorf > > Cc: Sara Golemon; PHP internals > > Subject: Re: [PHP-DEV] Scalar Type Hints v0.4 > > > > The inability to implicitly cast "123" to int is pretty much the KEY > > distinction between weak and strict scalar typehints (those pesky > > value-dependent type checks). If the strict typing mode doesn't = offer > > this, what's the point at all? >=20 > I am wondering what the point is indeed with preventing "123" to 123. = So far, all the concrete use cases people brought up > had to do with "Apple" or > "100 dogs", but nobody ever seems to be able to explain why converting = "123" > to 123 is likely to be a problem real world. Is it really just static = analyzers? >=20 Strict mode is useful in the sense that it prevents unnecessary implicit = conversions (which are costly) and it improves readability.=20 Following an example: function foo(string $x, int $y){ bar(1);=20 return strstr($x,"hello", $y); } function bar(float $a){} After adding the implicit conversions the code would look as follows: function foo(string $x, int $y){ bar((float) 1); return strstr($x, "hello", (bool) $y); } function bar(float $a){} In strict mode the original code would not be valid (rightly so IMO). = Just from reading the original code I would suspect that strstr expects = some kind of an offset (hence the int), therefore strict mode probably = revealed a bug.=20 And if not, then one can add the conversion manually. However, this is = not as trivial as it sounds. Personally I think it would only make sense = to have strict mode in PHP if the user had more strict conversion = functions at hand. What is the benefit of the following? if the = conversion to int is as sloppy as today then one does not gain anything = from the strict mode IMO: function foo(int $x){} foo( (int)$_GET["bla"]);