Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110648 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 79403 invoked from network); 18 Jun 2020 09:01:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jun 2020 09:01:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 12E5D1804CE for ; Thu, 18 Jun 2020 00:47:14 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 18 Jun 2020 00:47:13 -0700 (PDT) Received: by mail-lj1-f179.google.com with SMTP id q19so6069653lji.2 for ; Thu, 18 Jun 2020 00:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=J9zrviXD7HY1cP8aiebp1hVi4J4fUXvreZ7/q0hfu/0=; b=D0FnF9HI30Rh6TTMYZzx4XEWy44ahZOE3sF4kaOPj//m9uF5REHD2x99rdZTInRgnv YthvNqqHrs5wVA6QJvq93Nb3TaGWYDlPcfq5s+TFTqU8jUiW87S2JRCADgGKhfvqe/w0 /u+TDN3XLhhFNkwdL1xvgunlpX4Xdl4mOP6KOW32YEozGm0OZlHYasEUo0mpAstOElQH py6n6/rTkjsimVf0Y5/owRlc8NADrgWtnVqajx+Yx1k5cW0e0iT5zc0Hs3nWtnzc7End R4MXWmwB2k7E0Y6qq+9xGoNQgXxIqfaUqLE0poyClSmo1CFArnUMVOACzv4WvdztW/2B XekA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=J9zrviXD7HY1cP8aiebp1hVi4J4fUXvreZ7/q0hfu/0=; b=nWo05hTB5/1c4xqxetQr9LCJ8RJOD5TPnywCa5twTN8ZLhz84+eYzQoGI/5OSVHA5c i/7Hu8ge3ujoX5IlClDGpn7V2cgdFZvtpkx+RioIPpYxLC6F/jnSEs6cX+5MR+O9cZbu kYvulXijyU40AeoGG+h6n6+kcS01qa1RaQvfCevPDmI5Gk8iAw6lj2njWA6Qh9uS9gAe f7MXrtoktst+N3Xlop4HIiFaqjC2dCepPSQAhMeR+U7kzRGPVyGesuxmkvvPiDfUD5Nf IPzxtk9b7smDDcAMT354QcWnHkgjknmSBRySjJjPaOGCOZFDvUHXY3wxjz+V1ZrMN8vw OGCQ== X-Gm-Message-State: AOAM530rBL2vxuBLY8WxJni4JR6rVZSqbfyMqlUTXron2yonbhAVxE/q n18RUVQn9Q6WbUYzQeQLk8Xto9/7JC46A1DL26Y= X-Google-Smtp-Source: ABdhPJx3uq1c0Ak2PwMokv3wnh+5KQh6rfAsGUB6HCz5U/urdhXr0s+yrh/r6dMGIg6muEu6G4kZuOe9aq9oQpH9wPc= X-Received: by 2002:a2e:6a03:: with SMTP id f3mr1574159ljc.135.1592466432036; Thu, 18 Jun 2020 00:47:12 -0700 (PDT) MIME-Version: 1.0 References: <870E22A7-879D-415C-B7D0-71560B9CE156@gmail.com> In-Reply-To: <870E22A7-879D-415C-B7D0-71560B9CE156@gmail.com> Date: Thu, 18 Jun 2020 09:46:56 +0200 Message-ID: To: Claude Pache Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000ff931805a856fba9" Subject: Re: [PHP-DEV] [RFC] Treat namespaced names as single token, relax reserved keyword restrictions From: nikita.ppv@gmail.com (Nikita Popov) --000000000000ff931805a856fba9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 18, 2020 at 8:44 AM Claude Pache wrote= : > Hi, > > The following part of the proposal is problematic: Allow keywords in > definition of classes, functions, const, etc. > > class KEYWORD {}interface KEYWORD {}trait KEYWORD {}function KEYWORD() {}= const KEYWORD =3D 0;use Foo as KEYWORD; > > Under your proposal, the following code will compile without notice, but > will have a different behaviour from what the programmer intended: > > ```php > class Int { } > This part will still produce an error: "int" is not a reserved keyword, but it is a reserved class name, and handled by a different mechanism. const PRINT =3D 2; > const YIELD =3D 3; > > function foo(Int $b) { > return PRINT + YIELD; > } > ``` > Yes, this is the tradeoff :) We trade the ability to use reserved keywords in controlled situations, with potential confusion for cases like these. If it is important to allow to define classes, etc. with a keyword as name, > I suggest to force the programmer to say explicitly =E2=80=9CYes, it is r= eally what > I want=E2=80=9D. For example, something like the following: > > ```php > class namespace\Int { } > > const namespace\PRINT =3D 2; > ``` > This syntax doesn't make much sense to me. If we go down that line, I'd suggest something along the lines of Rust's "raw identifier" concept, which would allow you to write "const r#PRINT =3D 2" and "echo r#PRINT". This syntax would work everywhere identifiers are accepted, e.g. the "namespace iter\fn" would become "namespace iter\r#fn". The disadvantage of this approach is that it is not backwards compatible with PHP 7 and requires more active code change. E.g. the iter\fn example would "just work" under this RFC, while this approach would require rewriting the code. Nikita Another point which is problematic, is to allow `namespace` as a namespace > parts, since `namespace\foo`, although interpreted as a namespace-relativ= e > name, could be intended to be a qualified name by the programmer. > > =E2=80=94Claude > > > > > Le 16 juin 2020 =C3=A0 10:52, Nikita Popov a =C3= =A9crit : > > Hi internals, > > Inspired by the recent discussion on reserved keyword reservation, I'd li= ke > to propose the following RFC: > > https://wiki.php.net/rfc/namespaced_names_as_token > > This RFC makes two related changes: Treat namespaced names as a single > token, which enables use of reserved keywords inside them. And remove > reserved keyword restrictions from various declarations. > > The RFC comes with a small backwards compatibility break related to names > that include whitespace, but will hopefully reduce the backwards > compatibility impact of future reserved keyword additions. > > Regards, > Nikita > > > --000000000000ff931805a856fba9--