Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82201 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94570 invoked from network); 9 Feb 2015 00:05:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2015 00:05:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.199 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.199 imap11-2.ox.privateemail.com Received: from [192.64.116.199] ([192.64.116.199:49011] helo=imap11-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C5/8D-26926-6E9F7D45 for ; Sun, 08 Feb 2015 19:05:59 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id E13578800D5; Sun, 8 Feb 2015 19:05:55 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap11.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap11.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id iUaLy_rndrAk; Sun, 8 Feb 2015 19:05:55 -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 5DE018800E5; Sun, 8 Feb 2015 19:05:55 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) In-Reply-To: <54D7EF9D.7040700@gmail.com> Date: Mon, 9 Feb 2015 00:05:53 +0000 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <5E3D1500-E55D-4FEB-978B-FCA4AE4A1F13@ajf.me> References: <8703B53E-2C4A-4AC6-95C4-D4F19C6D5221@ajf.me> <54D7EF9D.7040700@gmail.com> To: Rowan Collins X-Mailer: Apple Mail (2.2070.6) Subject: Re: [PHP-DEV] Syntactical change to Scalar Type Hints RFC From: ajf@ajf.me (Andrea Faulds) Hi, > On 8 Feb 2015, at 23:22, Rowan Collins = wrote: >=20 > On 08/02/2015 19:44, Andrea Faulds wrote: >> Hi, >>=20 >> I=E2=80=99m posting this in a new thread since people might = (reasonably) be ignoring further responses to the [VOTE] thread. >=20 > Incidentally, you still used "reply" to create this message, so mail = readers which base threads on headers (e.g. Thunderbird) rather than = subject lines (e.g. GMail) still see it as part of the same thread = (though the subject line change makes it stand out, so I spotted it = anyway). Oh yeah, my bad. :/ >=20 >> I=E2=80=99m considering a small change to the Scalar Type Hints RFC, = specifically about syntax. Quite a few people have said they don=E2=80=99t= like the declare() syntax, and it=E2=80=99s easy to see why. It=E2=80=99s= rather verbose, it has all the quirks of declare() (such as block = syntax, not respecting scope), and it=E2=80=99s rather ugly. >>=20 >> Instead, I=E2=80=99m wondering if the following might be better: >>=20 >> >=20 >> Which would be used like so: >>=20 >> >=20 >> function foobar(): int { >> return 1.0; // error! >> } >>=20 >> It=E2=80=99d be a per-file directive, so there=E2=80=99d be zero = mixing of modes within one file, and you=E2=80=99d avoid the quirks of = declare(). >=20 > I find this much, much uglier than declare(). >=20 > Firstly, it seems to be creating a whole new syntax convention, which = will need its own rules - Can it be preceded by a newline or other = whitespace? Must it be followed by a newline (unlike a normal "=E2=80=9D? Secondly, it is less specific than the current proposal - it suggests = that PHP has a generic "strict mode", rather than a "strict = type-checking" mode. It could be renamed to strict_types, but that loses some elegant. > Would more "strict" features be added to this mode later? No. > Or would other keywords be added so that you could, ahem, "declare" = several directives at the top of your block? No. > Thirdly, it has all the same scoping issues as declare() - you can = break a function up into multiple blocks, so it's still = possible to switch it halfway through a declaration, I=E2=80=99ve already sent an email in this thread about possible = approaches to handling multiple blocks. My preferred solution would not = allow what you describe, and instead behave like namespaces (must be in = first block, affects entire file). > If this magic token has the extra effect of causing ?> to be ignored, = that's a fairly major and unrelated feature, which would probably need = its own RFC. ?> isn=E2=80=99t ignored - PHP blocks aren=E2=80=99t, and never have, = been considered the same as separate files. > If you make the first " Test It's not like non-block namespace declarations having to be at the top = of the file, because that is still a separate statement, it just has to = be the *first* statement; whereas this appears to be designed to merge = with the non-statement opening tag. Is there really an important difference between first statement, and = first opening tag? The main difference in behaviour is empty blocks. > If you're going to go that far, why not just disallow the block-level = syntax of declare() for this case, if that is the complaint? Or if the = problem is the non-block syntax, why not enforce that a non-block = declare(strict_types) be at the top of the file? Well, it=E2=80=99s not just that which is the problem: declare() is = rather verbose and ugly. Also, having it behave differently from all = other declare() statements would bring into question why we even bother = reusing the declare() syntax. -- Andrea Faulds http://ajf.me/