Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80456 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73146 invoked from network); 14 Jan 2015 11:10:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jan 2015 11:10:54 -0000 Authentication-Results: pb1.pair.com header.from=narf@devilix.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=narf@devilix.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain devilix.net designates 209.85.218.43 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.218.43 mail-oi0-f43.google.com Received: from [209.85.218.43] ([209.85.218.43:44011] helo=mail-oi0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1C/12-61073-DBE46B45 for ; Wed, 14 Jan 2015 06:10:54 -0500 Received: by mail-oi0-f43.google.com with SMTP id i138so6812757oig.2 for ; Wed, 14 Jan 2015 03:10:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devilix.net; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=h5APrdolPAXhNaZT29rY+2LGBYS+o4u80iulskSR3eI=; b=pQ1qe5pGt1QBzBr4M30iPT/a4tnIpd4vwuiPNh4IPZg4mRaCTAzzcOKZVBbLH3mqiQ iQ9StFFjF82KUKVYfSUJaAYZeF6RneScgKlk7Aqk/GcS6Ie0E0SneJr7QKQSrWcEXJz3 edrgneFS0czzf7XPcaJQUtOZ7DmF7ojxAzFco= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=h5APrdolPAXhNaZT29rY+2LGBYS+o4u80iulskSR3eI=; b=MUNtImeNFerqlYaL8sPZtkIjwC62zD31DgkUze6rDUkaGLARB17yQwl7qGILBlCyzI bkQi/6PAHKpRhe66o3sss2fr5va6YOaBKjjISkxovUSnjvL3LYE0Yk37b5sKRPmctqSP fXi5vAgXRnYXt43IS/pvDw8jQeYmCNNjcurZJjRPNFZXEadbFLMAnJzD+99UrFcQW0oO nafsU3W3O7exMMYhHJlOzA6Kn/1d1vBYHkjJAGGQSFpmMyOVVH/6khjqIbsVOYJpI1DW 9yb2ChrgLoH93KAatUxUdg8p8L6b8qZv17bNxa6/XRm+L1Uhk3b9flu9V4ymSF9tixgB xKpw== X-Gm-Message-State: ALoCoQmJ82JXgn1Oco7SX6ZHGRVWo/QCwR332k1f0Z7hfYc6jhogA5gkJVt3faGTGbbDi5msJNl/ MIME-Version: 1.0 X-Received: by 10.182.126.197 with SMTP id na5mr2109720obb.2.1421233851091; Wed, 14 Jan 2015 03:10:51 -0800 (PST) Received: by 10.202.214.146 with HTTP; Wed, 14 Jan 2015 03:10:50 -0800 (PST) In-Reply-To: <76F9DAD3-5A22-4A53-8262-CF6B33D80FC3@ajf.me> References: <8DCD1B72-C81D-499E-B455-E4A042CD76E6@ajf.me> <76F9DAD3-5A22-4A53-8262-CF6B33D80FC3@ajf.me> Date: Wed, 14 Jan 2015 13:10:50 +0200 Message-ID: To: Andrea Faulds Cc: Julien Pauli , PHP Internals List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints v0.2 From: narf@devilix.net (Andrey Andreev) Hello, On Wed, Jan 14, 2015 at 12:22 PM, Andrea Faulds wrote: > > Hi Julien, > >> On 14 Jan 2015, at 10:14, Julien Pauli wrote: >> >> Using declare() IMO, is a PITA. >> Everything that can be done without the use of declare(), must be done w= ithout declare(). >> >> I would have prefered different syntax, like the ones we disccussed many= years ago , having strict checks with the foo(string $a) syntax, and non-s= trict check with the foo((string) $a) syntax. > > Actually, this approach came about mostly to avoid that. I don=E2=80=99t = really like the idea of mixing and matching weak and strict type checks. Ha= ving some functions using (int) and (string), others use int and string, an= d others still use both, would be confusing. Plus, it would mean that you= =E2=80=99d be forced to follow the personal preference of the API authors. > > With this RFC, yes, you have to put an extra line at the top of the file.= But it has the advantage that everything follows the same behaviour, even = extension/built-in functions. That=E2=80=99s what I like about it. I don't understand why it should be a bad thing that the API author forces rules on the consumer. The opposite is IMO fundamental to the concept of an API - the rules specified by the author are a contract that the consumer agrees to, and which allows for the whole thing to work properly. In this form, I don't get any benefit from strict type checks, because I only want them so that writing foo(int $bar) guarantees me that the caller *passed* an integer. Instead, I'd have to NOT use a type hint, and instead do an is_int($bar) check inside ... this beats the whole purpose. This caller-controlled switch very much reminds me of mbstring.func_overload, which I didn't care much for, until one day I saw how it breaks all crypto code that authors had otherwise written very carefully. I prefer Julien's (int) $weak vs. int $strong syntax better (which is what I've always wanted), but I don't care much if it's a declare() statement, just as long as the author controls the behavior. And while I'm on that - thank you for this proposal (specifically the 0.2 version), Andrea. Finally an RFC that allows both weak and strict scalar type checks instead of the "can't go in both directions" nonsense that has blocked this feature for years. Cheers, Andrey.