Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82102 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56439 invoked from network); 7 Feb 2015 22:11:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Feb 2015 22:11:56 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.199 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.199 imap11-2.ox.privateemail.com Received: from [192.64.116.199] ([192.64.116.199:53890] helo=imap11-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D7/C0-50836-7AD86D45 for ; Sat, 07 Feb 2015 17:11:54 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 387A08800E6; Sat, 7 Feb 2015 17:11:49 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap11.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap11.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id H766x4_yhH-g; Sat, 7 Feb 2015 17:11:49 -0500 (EST) Received: from oa-res-26-240.wireless.abdn.ac.uk (oa-res-26-240.wireless.abdn.ac.uk [137.50.26.240]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 5AE848800E2; Sat, 7 Feb 2015 17:11:48 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) In-Reply-To: Date: Sat, 7 Feb 2015 22:11:45 +0000 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <2C5FA029-7AA6-4707-ADF1-129194C2B53A@ajf.me> References: <8703B53E-2C4A-4AC6-95C4-D4F19C6D5221@ajf.me> <9E1C2427-0295-4F3E-BD29-04DA84321067@ajf.me> To: =?utf-8?Q?Pavel_Kou=C5=99il?= X-Mailer: Apple Mail (2.2070.6) Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints From: ajf@ajf.me (Andrea Faulds) Hi, > On 7 Feb 2015, at 22:03, Pavel Kou=C5=99il wrote: >=20 > On Sat, Feb 7, 2015 at 9:57 PM, Andrea Faulds wrote: >> Hi, >>=20 >>> On 7 Feb 2015, at 20:47, Andrea Faulds wrote: >>>=20 >>>> On 7 Feb 2015, at 10:57, Pavel Kou=C5=99il = wrote: >>>>=20 >>>> I just realized it now (I brought it up in a different manner when >>>> there was discussion about the RFC), but I didn't notice there was = a >>>> totally false statement about it in the RFC itself. You probably >>>> should fix it. I'm speaking about the "Strict type checking, which = is >>>> used by many popular programming languages, particularly ones which >>>> are statically-typed, such as Java, C#, Haskell, or Facebook's = Hack. >>>> It is also used for non-scalar parameter type hints in PHP. With = this >>>> approach, an argument is only accepted if its type is exactly the = same >>>> as the parameter." paragraph. >>>>=20 >>>> This is NOT true (at least for C# and Java), as you can read here = in >>>> the documentations of respecitve languages so you should not = compare >>>> the strict version of the typing implemented in PHP with other >>>> strongly typed languages, because the PHP's "strict" is stricter = than >>>> strongly static typed languages. I really hope noone voted with the >>>> thought that the strict typing acts as it does in Java and C#. >>>>=20 >>>> https://msdn.microsoft.com/en-us/library/y5b434w4.aspx >>>> = http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 >>>=20 >>> I don=E2=80=99t think it=E2=80=99s unfair. There=E2=80=99s a limited = set of permitted conversions in some strictly-typed languages, but = it=E2=80=99s still strictly-typed. >>=20 >> To add to the previous email: >>=20 >> * Most of these conversions are between different sizes of the same = type (float/double, char/short/int/long, etc.), but this is irrelevant = to PHP which has only one size for each type >> * The other ones are between types (int to float) >> * Always allowing implicit conversions from float to int is very = likely to cause data loss, so it=E2=80=99s not unreasonable for PHP to = prevent this specific case >> * Always allowing implicit conversions from int to float is sometimes = going to cause data loss, so it may also be reasonable for PHP to = prevent this specific case >> * Requiring an exact type match has the least mental overhead, and = allows types to be checked at compile-time >>=20 >=20 > Yeah, but you say in the RFC that "With this approach, an argument is > only accepted if its type is exactly the same as the parameter." when > speaking about C# and Java - which is NOT true. C# and Java aren=E2=80=99t really considered weakly-typed. Technically = they=E2=80=99re not =E2=80=9Cfully strict=E2=80=9D I guess, but if you = were to give example of strictly-typed languages, you=E2=80=99d probably = include C# and Java in that list - so I did. > You should have > written that the way of strict typing in PHP is even more strict than > Java's and C# one - because the way it's written now is unfortunately > misinforming the readers of the RFC. It might be somewhat misleading. Really, what=E2=80=99s =E2=80=9Cweak=E2=80= =9D and what=E2=80=99s =E2=80=9Cstrict=E2=80=9D is rather subjective: C = is sometimes considered weak, sometimes strict. I=E2=80=99d say it=E2=80=99= s more =E2=80=9Cweak=E2=80=9D because all sorts of definitely wrong = conversions are allowed implicitly and merely generate warnings. C# and = Java are more careful here, so I=E2=80=99d say they=E2=80=99re = =E2=80=9Cstrict=E2=80=9D even though I suppose they do have a degree of = weak typing. > Also, there's no need to mention > float -> int, because that one is definitely wrong. But for the int > (and long, etc) -> float (and double) - how do the languages you > mentioned in the RFC handle that conversion? =46rom Microsoft=E2=80=99s documentation that you linked, it sounds like = they just always convert and never error, so you=E2=80=99d get data loss = in some cases (just like you do in PHP with an explicit cast). > I'm wishing more and more that the RFC doesn't pass (even though I'd > LOVE to have typehints in PHP as a userland developer) and someone > else will make a better version of typehints RFC for PHP 7, because > this one feels really like you took an ok-ish RFC (one that would be > good for PHP) and slapped a strict typing on it without enough > research about strong typing in other languages. I am familiar with other languages, I just disagree with their approach. > And as I said myself > multiple times in the past, the declare syntax IS just ugly (and > changing how code works by writing one line is an ugly principle as > well, IMHO). :( I prefer this approach to the inconsistency the other approaches = suggested thus far lead to. -- Andrea Faulds http://ajf.me/