Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75547 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79650 invoked from network); 15 Jul 2014 14:30:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jul 2014 14:30:44 -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.44 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.44 mail-wg0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:38867] helo=mail-wg0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B0/10-15121-21B35C35 for ; Tue, 15 Jul 2014 10:30:43 -0400 Received: by mail-wg0-f44.google.com with SMTP id m15so5671106wgh.15 for ; Tue, 15 Jul 2014 07:30:39 -0700 (PDT) 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=wlsaP8XK4ZtFLx4OGEtCuhoZSF0lbl026YEFOZG6w18=; b=sgAzu6JIbh03Zci8nDD4GOnfdHaCvXl8NNxf6T7IeCYt7l23TPnrzLdzHFKcH+WYyB nF1iexu22Y38LwV4M9uXUNWHXUjpEnbfpnX5c9ehJU58X7gyzH5ESp7bTsBx0iAtwveH 774iQdQGkvApRBSminZLgWisQ1WkWwReZJ0+dclNq/oEXU+nK5uOtW7tii+f0/3//Mi3 bYXDmx4uFFfvvCcxx4ESbm8g35zRLZ/LcvB+RlnRTBiuDp/APSW1nPj+yo3Id7zzUXMb cZMt/EiUMGQRLPMmc48MXcuFsMYKikvq6DV/7xw/wc+ee2aLmjVmMlC+d7qUHS62vVhA 4rqw== X-Received: by 10.180.95.136 with SMTP id dk8mr6136926wib.8.1405434639704; Tue, 15 Jul 2014 07:30:39 -0700 (PDT) Received: from [192.168.0.139] ([62.189.198.114]) by mx.google.com with ESMTPSA id l2sm32990838wjw.31.2014.07.15.07.30.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Jul 2014 07:30:38 -0700 (PDT) Message-ID: <53C53A96.2040303@gmail.com> Date: Tue, 15 Jul 2014 15:28:38 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: internals@lists.php.net 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> In-Reply-To: <53C460DF.5040304@sugarcrm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: rowan.collins@gmail.com (Rowan Collins) Stas Malyshev wrote (on 14/07/2014): > But I'm not sure why you need this. You accept that if("foo") > works. Then why "function foo(bool $x) { if($x) { ... " should work > differently? The answer - which is definitely a matter of opinion - is that allowing any string reduces the usefulness of the type hint. I realise there is not consensus on whether scalar hints should represent validation, cast, or a mixture, but *if* we go down the route of validation, then we have to choose which values are valid and which are not. My preference is to keep that strict: the example others have posted of some_func($foo & BIT_FLAG) seems no more like a "real" boolean to me than some_func(strlen($foo)) or any other expression which yields an integer. In fact, I'd find the behaviour more obvious if it were written some_func((bool)$foo & BIT_FLAG) - it makes clear that some_func is not itself aware of the flag, that's just the caller's way of making the decision. That the type hint encouraged that would therefore seem like a Good Thing. (I'd post that comment on the appropriate sub-thread where that example was raised, but don't have time to find it...) Regards, -- Rowan Collins [IMSoP]