Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80644 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14025 invoked from network); 16 Jan 2015 14:53:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jan 2015 14:53:13 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.182 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.182 mail-we0-f182.google.com Received: from [74.125.82.182] ([74.125.82.182:47595] helo=mail-we0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 91/42-00273-8D529B45 for ; Fri, 16 Jan 2015 09:53:13 -0500 Received: by mail-we0-f182.google.com with SMTP id w62so20579475wes.13 for ; Fri, 16 Jan 2015 06:53:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=2V18NAuNoatL2NjkAcIlgRR2HQ0Ar/0d3zKPAfs3NRo=; b=SXiWQq+xuvsElYJPH962uiuO1XYELXLLSSknS2Hm239ODpB++AQSBsmTlJ5dMfqQ3L IfIc1I7fHlXT0bkNDV141jhKY56WmRluVJXWZ0GlviOUBdkBdAAFJ9W1lIlrk57VmgaG JQe4NROI+NpwhB/SYo5o8+42BIM/A+6sJGjmyFTxWZ93tlUOjXw+/nOcAtj/Tk++IquM Z1TsK8auBsiM1fIOAA/yoiCtUVU0a/Pq+7zj0u4SIbwac02kBf7zzeAHL3n37+VW8DLl G+mQ4XhXxtQsHN4PRMQ7eu+0GBpblUAA0XTHDfp3LWPFSI7IVYvvE5wbXAw7BUOHdL1x NRIQ== X-Received: by 10.180.218.39 with SMTP id pd7mr7037613wic.21.1421419989331; Fri, 16 Jan 2015 06:53:09 -0800 (PST) Received: from [192.168.0.172] ([62.189.198.114]) by mx.google.com with ESMTPSA id bo3sm6343904wjb.44.2015.01.16.06.53.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jan 2015 06:53:08 -0800 (PST) Message-ID: <54B925B8.1010601@gmail.com> Date: Fri, 16 Jan 2015 14:52:40 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: "internals@lists.php.net" References: <8DCD1B72-C81D-499E-B455-E4A042CD76E6@ajf.me> <4E2073DE-0951-498C-97BB-DDAC094F11FA@ajf.me> <9a033dd1f223f854e760924d118ab812@mail.gmail.com> <2ae0164cb9b9bf1c974d7a3c60af0466@mail.gmail.com> <6105ea99002e634373c09685310e26a6@mail.gmail.com> <54B90431.10903@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints v0.2 From: rowan.collins@gmail.com (Rowan Collins) Andrey Andreev wrote on 16/01/2015 13:00: > Hi, > > On Fri, Jan 16, 2015 at 2:29 PM, Rowan Collins wrote: >> Mike Willbanks wrote on 15/01/2015 16:55: >>> It also means that then a library developer would >>> need to handle conditions on both sides (when in weak vs. strict). So I >>> don't really understand where the gains of this would come from and it >>> actually causes me concern in that what if a developer forgets to define >>> strict and you're entire system is built on strict. >> >> In case this hasn't been repeated enough times already: No They Would Not. >> >> As a library developer, you do not rely on strict or weak hints, you rely on >> the variables you receive being of the types you require. This is guaranteed >> in both modes. >> >> You cannot stop the user of your library doing whatever it takes to get past >> your validation. It is up to them to provide sane inputs to your published >> API, and no version of type hinting can change that. > This is mostly true, but relying on the variable that you receive > inside a function is different from relying on the variable that gets > passed to a function. > > Yes, there will be users who will simply do an explicit cast, but > there will also be users who will take notice of the produced error, > and ask themselves why first, instead of immediately trying to > "override" it. > > Many developers want to do that, regardless of the reasons why. Some > just like the strict philosophy better, some see it as a way of > educating their users, and others use it sparingly. Try arguing with > anybody writing crypto code and they will all tell you that any case > of uncertainty must be handled with a *hard* failure. > > You may not agree that it is necessary, but that doesn't make it > invalid. And intentionally allowing only one guaranteed behavior does > imply that the other is invalid. > > For the Nth time - if I want to achieve that effect, I will code for > both cases by not using the feature and doing is_int(), is_string(), > is_bool(), etc. checks, so the language might as well help me do it. I > would understand if it was not helping with something that's just > wrong, but this is not the case at all here. OK, point taken. I do think that it's a bad idea for library authors to do that, so don't think the language should make it easy, but I understand that some people want to do it. Specifically, I don't think a library author should be able to tell me that, just because they're feeling picky, '42' and 42 are not equivalent when calling their function. It does very little to protect me from genuine mistakes (passing completely the wrong parameter), and makes my life as user of the library harder. But then, fundamentally, that's the argument against having strict typing full stop, and it's painfully clear that there's a big divide of opinion on that. Regards, -- Rowan Collins [IMSoP]