Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81854 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40800 invoked from network); 5 Feb 2015 01:16:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2015 01:16:01 -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.200 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.200 imap1-2.ox.privateemail.com Received: from [192.64.116.200] ([192.64.116.200:33429] helo=imap1-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 49/A1-40930-054C2D45 for ; Wed, 04 Feb 2015 20:16:00 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 23624B0007B; Wed, 4 Feb 2015 20:15:58 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap1.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap1.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id tcJP7CmEEUU5; Wed, 4 Feb 2015 20:15:58 -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 8094FB00085; Wed, 4 Feb 2015 20:15:57 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) In-Reply-To: <5B.1F.40930.B23B2D45@pb1.pair.com> Date: Thu, 5 Feb 2015 01:15:55 +0000 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <8DCD1B72-C81D-499E-B455-E4A042CD76E6@ajf.me> <5B.1F.40930.B23B2D45@pb1.pair.com> To: Pascal Chevrel X-Mailer: Apple Mail (2.2070.6) Subject: Re: [PHP-DEV] Re: [RFC] Scalar Type Hints v0.2 From: ajf@ajf.me (Andrea Faulds) Hi Pascal, > On 5 Feb 2015, at 00:02, Pascal Chevrel = wrote: >=20 > I am probably going to ask a stupid question, but do we really need = the =3D1 part in declare? >=20 > declare(strict_types=3D1) couldn't be declare(strict_types)? >=20 > Or does it mean that there would be cases when strict typing would be = deactivated after being activated with declare(strict_types=3D0)? Oh, I made it like that because that=E2=80=99s the existing syntax of = declare(), it takes a name and a value. But I suppose it could be = modified to allow just a name. I don=E2=80=99t think we should modify it = just for this specific case, really=E2=80=A6 less exceptions to a rule = and more consistency are generally a good thing. There is a use for declare(strict_types=3D0), which is to make part of a = file weak while having the rest strict. It=E2=80=99s not something = you=E2=80=99d want to do very often, but it may be useful in some rare = cases. If we have declare(strict_types=3D1), then it makes sense to also = have declare(strict_types=3D0). It=E2=80=99d be rather odd to not allow = it. > To be honest, I don't like declare() because it looks like a function = call, not a setting for the file like a namespace declaration would be. = Also, in the case of declare(ticks=3D1), 1 is not a boolean but an = interval so I find it a bit confusing that strict_types=3D1 would be a = boolean in that case. Or maybe declare(strict_types=3Dtrue) then? I originally had it be a boolean, but considering how often this would = be used, I changed it to 1 for terseness. Using 1 is common for INI = settings, so I don=E2=80=99t think it=E2=80=99d be that confusing, but I = see your point. > Personnally I would prefer a syntax like: > declare strict; >=20 > which is just shorter and more readable in my opinion. I know it is = mostly cosmetic but I don't really understand why declare uses = parenthesis if it is a language construct and not a function (and yes, I = think that declare(ticks=3D1) also looks silly ;) ); >=20 > So basically instead of that at the top of my files: > namespace Foo; > use Bar; > declare(strict_types=3D1); >=20 > I would prefer having that: > namespace Foo; > use Bar; > declare strict; >=20 > It's probably a detail in the whole discussion, but for some weird = psychological reason, it matters to me :), I can see the appeal, though I=E2=80=99m not really sure about adding = new syntax just for this. By the way, I think declare() would be easily distinguished from a = function for two reasons. Firstly, you can=E2=80=99t assign to = constants, and secondly, it=E2=80=99ll be syntax-highlights differently. I can understand your concerns, though. :) Thanks for voicing them. -- Andrea Faulds http://ajf.me/