Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75598 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32022 invoked from network); 16 Jul 2014 19:45:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2014 19:45:30 -0000 Received: from [127.0.0.1] ([127.0.0.1:1361]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 54/45-31820-A56D6C35 for ; Wed, 16 Jul 2014 15:45:30 -0400 Authentication-Results: pb1.pair.com smtp.mail=prvs=227422f2c5=jwatzman@fb.com; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=jwatzman@fb.com; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain fb.com does not designate 67.231.153.30 as permitted sender) X-PHP-List-Original-Sender: prvs=227422f2c5=jwatzman@fb.com X-Host-Fingerprint: 67.231.153.30 mx0b-00082601.pphosted.com Linux 2.5 (sometimes 2.4) (4) Received: from [67.231.153.30] ([67.231.153.30:27982] helo=mx0a-00082601.pphosted.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DA/54-31820-007C6C35 for ; Wed, 16 Jul 2014 14:40:01 -0400 Received: from pps.filterd (m0004003 [127.0.0.1]) by mx0b-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id s6GIcqIU011877; Wed, 16 Jul 2014 11:39:56 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=facebook; bh=u3qo/O7guFUiRmgkrmXIqJ7ePVgN03bWGGi9/wHsYX0=; b=rQmktdxWQRfFZgwDhjyD6BlTk/OPeDf5gQy5CO0lncbV1aVgu29EPxjKQ3zYHj6shjk9 NXy4s8SQhAocmHV4/sk3KB/o4Ez9b+8KO1jzjtTaiGtQmJnLZZ9yQg5UJK4fr1uTz/bz YulSA/OUytbtHoDTjHwyaecxRhkj1ak/ExU= Received: from mail.thefacebook.com (mailwest.thefacebook.com [173.252.71.148]) by mx0b-00082601.pphosted.com with ESMTP id 1n5jrwa5m1-2 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK); Wed, 16 Jul 2014 11:39:56 -0700 Received: from PRN-MBX02-2.TheFacebook.com ([169.254.5.125]) by PRN-CHUB10.TheFacebook.com ([fe80::c983:d64f:e422:461d%12]) with mapi id 14.03.0174.001; Wed, 16 Jul 2014 11:39:55 -0700 To: Andrea Faulds CC: Zeev Suraski , Rowan Collins , "internals@lists.php.net" Thread-Topic: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) Thread-Index: AQHPnj3hxlB2fkX7N0aer00oN4qWGJuf/3WAgAAJrwCAAAEEAIAAnU6AgAEDiQCAAB1pAIAAE5qAgAAnAACAAAFHgIAA5WOAgAAPkwCAAAs4gIAAFFEAgAAC3ACAABq3gIAATUAA Date: Wed, 16 Jul 2014 18:39:54 +0000 Message-ID: References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <16D48604-0C0A-4613-91A4-21392E3A2636@ajf.me> <05CE2216-C5D9-4937-9F2E-AA1407284D9F@ajf.me> <53C460DF.5040304@sugarcrm.com> <53C53A96.2040303@gmail.com> <53C55342.1010207@sugarcrm.com> <53C563B3.6060905@gmail.com> <54536191-1B92-4933-973F-0C8289D13A4C@ajf.me> <00d12255efc53466245b21a83ff7d474@mail.gmail.com> <53C652FA.6010704@gmail.com> <53C66D6E.9060200@gmail.com> <60f496756412de6ad97751d91ead5058@mail.gmail.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.16.4] Content-Type: text/plain; charset="Windows-1252" Content-ID: <6FE707E47F935A4ABA4F74B6CEC6D35A@fb.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.12.52,1.0.14,0.0.0000 definitions=2014-07-16_07:2014-07-16,2014-07-16,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 kscore.is_bulkscore=0 kscore.compositescore=0 circleOfTrustscore=29.8995380443607 compositescore=0.322287768733618 urlsuspect_oldscore=0.322287768733618 suspectscore=0 recipient_domain_to_sender_totalscore=20 phishscore=0 bulkscore=0 kscore.is_spamscore=0 recipient_to_sender_totalscore=0 recipient_domain_to_sender_domain_totalscore=2524143 rbsscore=0.322287768733618 spamscore=0 recipient_to_sender_domain_totalscore=2 urlsuspectscore=0.9 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1407160209 X-FB-Internal: deliver Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: jwatzman@fb.com (Josh Watzman) On Jul 16, 2014, at 7:03 AM, Andrea Faulds wrote: > On 16 Jul 2014, at 13:28, Zeev Suraski wrote: >=20 >> It's more of a lossy cast, exactly as we have today, that has an >> (effectively-optional-since-it's-off-by-default) to warn you about loss = of >> data. >> For the vast majority of users who use the defaults, there'll be nothing= new >> to learn except for the availability of those implicit casts in function >> signatures. >> For those who want to take advantage of 'loss protection', they'd have t= o >> learn about this extra warning type and clean their code so that it adhe= res >> to it. But there too, they'd have consistency, just one set of rules fo= r >> implicit cast of scalar values across all of PHP. >=20 > The problem with making this RFC do the lossy thing is it then removes on= e key advantage of it: that this RFC provides a measure of strictness. With= out that, we have no real compromise proposal, and we might as well introdu= ce a second set of =93strict=94 type hints. The whole point of the current = behaviour is that it compromises between the weak typing and strict typing = camps; doing what zpp does is giving in to the former camp, and then it=92s= not a compromise any more, is it? This is exactly why I really like this proposal. While I love the idea of s= uper strict type annotations, I totally understand why they shouldn't be ad= ded to PHP. The RFC as it stands strikes a great balance between keeping wi= th "the PHP way" of weak typing, while still making scalar type annotations= useful. If I'm writing an app and an API I'm using has been annotated to take an "i= nt" parameter, and I pass something that cannot possibly be an int, I want = to know that, I want to know it *now*, and I don't want the program to keep= executing (possibly writing bad data to a database or doing any number of = other crazy things that could happen when my not-an-int gets converted to a= n int). The entire utility of the type annotation there is that the API dev= eloper has said "I expect an int here, if you don't pass one, you're not us= ing the API correctly". As others have argued, the API could technically im= plement the "lossless conversion" logic itself, but it's fiddly at best to = get right, and very error-prone. In the other direction, if the API really = does want a cast-to-int-no-matter-what, it can just omit the type annotatio= n and do that -- it's easy and not at all error-prone. I understand the argument about consistency, but I think this can be mitiga= ted if you couch the feature correctly when documenting it, announcing it, = etc, so that people get the right mental model in their heads when they fir= st hear about it. I wouldn't talk about the type annotations this RFC propo= ses in terms of casts, since they aren't really quite casts (as the folks m= aking the consistency argument have stated). They're something else -- they= 're type annotations (or type hints, or whatever you want to call them). In= that vein, they are *consistent* with the existing strict enforcement of o= bject type annotations, with the added detail that "strict enforcement" for= scalars is defined in terms of "lossless conversion" as outlined in the RF= C, since that's the "PHP way" of loosely dealing with scalar types. The ide= a of "lossless conversion" has just never been relevant before since there = is no such thing as a lossless conversion to any object type, or from any t= ype to an array -- but it's a completely consistent way of extending the wa= y we deal with the existing annotations. (And not inconsistent with casts s= ince it isn't a cast!) Josh Watzman