Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83356 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26287 invoked from network); 20 Feb 2015 21:09:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Feb 2015 21:09:41 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.50 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.215.50 mail-la0-f50.google.com Received: from [209.85.215.50] ([209.85.215.50:38426] helo=mail-la0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D3/72-14173-392A7E45 for ; Fri, 20 Feb 2015 16:09:40 -0500 Received: by lamq1 with SMTP id q1so8650006lam.5 for ; Fri, 20 Feb 2015 13:09:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=V/oWq+HPFE5L8bOQfsZF2/MRmdzQwkDSflTCSx45vRk=; b=WJyEzSLz+1cCjIBf4wUvcMkSXr/BdA+Qylh6RYbbYs6Y8CRI4Uj//rD6QZkiZcBMEl utsXuv6wYWmggsc9oBC2WiN84bLmO10pqL9fMfCqv1vvNxk+8PuewgQdFEKR87o7M2v3 ONogq5Xcvf7CoNF1tsg1V+an8jyCOHhCDTok4VaB4LbjSTkrPEP5gVlXTbXHw8Lrgjw9 +gfySA+HR3pnUfaBvejB/eadoElSVihlBk3x4BuAyMqQ65vrdnCNkdnXD0iyHXzQlqd2 Mc0pvnBayFkGZKpOCyck/B58ISSj20+8sF3/s9OKNu9UjVIHajB/3ryRTeSSLgszjkIt frKQ== MIME-Version: 1.0 X-Received: by 10.112.170.72 with SMTP id ak8mr9678042lbc.95.1424466575262; Fri, 20 Feb 2015 13:09:35 -0800 (PST) Received: by 10.25.43.9 with HTTP; Fri, 20 Feb 2015 13:09:35 -0800 (PST) In-Reply-To: References: Date: Fri, 20 Feb 2015 16:09:35 -0500 Message-ID: To: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [RFC-Discuss] Scalar Type Declarations v0.5 From: ircmaxell@gmail.com (Anthony Ferrara) All, > An interesting point was brought up related to block mode: > https://twitter.com/drrotmos/status/568540722586107904 > > Namely that generated file caches may need the ability to switch block > mode on-and-off. > > I'm considering making the change to add that. If that happens, > declare must be the outermost block, and no non-declare blocks would > be allowed in the outermost scope of the file: > > declare(strict_types=1) { > //... > } > declare(strict_types=0) { > //... > } > > Having trailing code or code outside of the declare would be a compile error. > > declare(strict_types=1) { > //... > } > foo(); // compile error > > This behaves consistent with namespace block-mode today (though the > strict type declaration would be required to be outside the namespace > block). > > I'm considering adding it, as it's a valid use-case. What do you think? So, I ran into a snag while doing this. It turns out that in the parser implementation of declare is not going to allow it without significant restructuring (including a lot of validation in the compiler): declare_statement: statement { $$ = $1; } | ':' inner_statement_list T_ENDDECLARE ';' { $$ = $2; } ; So in block mode, declare supports inline, block and named-block mode: declare(...) foo(); declare(...) { foo(); } declare(...): foo(); enddeclare; The problem with this is that namespace declarations can only happen in top_statement (along with some other statements). That leaves two options to support multiple modes per file: 1. Allow in top-level only: declare(strict_types=1); namespace Foo { } declare(strict_types=0); namespace Bar { } 2. inside of the namespace: namespace Foo { declare(strict_types=1); } namespace Bar { } The problem with the first is clarity (it's easy to miss a declare and not understand that the mode has changed). We pinned declare to the top of the file for clarity. I'm not sure this use-case is worth breaking that clarity. The problem with the second is more subtle. With the current parser+compiler, that declare would affect the entire file. It would take pretty significant changes and restructuring of the parser to effect. We could drop declare() all together and go with something like a namespace modifier: strict namespace Foo { } namespace Bar { } But I don't think it's worth it to conflate those two together. Though if we did, the syntax "strict namespace;" would be supported for non-namespaced strict code. So in the end, my conclusion is that while it would be nice to support the "compiled file" use-case fully, it's not worth it from a technical level (the risk and degree of change required doesn't offset the benefit of it). So the proposal will remain unchainged and not support the block syntax (or changing the mode mid-file). Thanks Anthony