Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111244 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74871 invoked from network); 29 Jul 2020 08:28:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Jul 2020 08:28:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C46991804D1 for ; Wed, 29 Jul 2020 00:24:07 -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-Virus: No X-Envelope-From: Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 ; Wed, 29 Jul 2020 00:24:07 -0700 (PDT) Received: by mail-lf1-f46.google.com with SMTP id j22so6540011lfm.2 for ; Wed, 29 Jul 2020 00:24:07 -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=ObYMjVzTE7K82qbFpcSEspLddMO5cgVKVdx9UDSp4JQ=; b=eLNrHY13TlkrA0LCTr4ob2ofIGjL/iP9odNbdV4ojFOKIhAwLI9S46B0hwSo5cY7Vs 1DkgitnO+3SQF2OgHzKSPwOxmCbv2JID59ebJwdfk1PI9rAKAGTTeXcVi9tyLMDPoK1W UcokIttGYAmpSe7Q2gGgSNzLwsHIVpwPbz11RAfEhBlcSPofFdtbW9IwNWfvF4hZnyBK zeXN31PKOQXR0M3RS2MfTs3lwUJY8ayrYBJAM0TMwsjImg2ZypOCdqVBUjLENbdn4Vfj r52tfh/niIK6hD5gbkDLe6M1LUcgctar4nxBOH01kbmOxfcvcthINHX87HbREfgrFfLL 0T0A== 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=ObYMjVzTE7K82qbFpcSEspLddMO5cgVKVdx9UDSp4JQ=; b=o6E/93svY7NuBCX5X6fEWHroahmidU1V1Lb6N+QIJOwtiotwN6xG4VXzkwZaAqRFIq vsbhLDpyAHBlnHZeZhlswChPAA/CJcu12Hj1H4H/ZwaIiV96C/RslJB3E/WlgAJ9LuDZ jeqyRIVgY5CntugXFAN/O/abUYxdMJXiDDfEZ45SD2unumkZIvHAjyHiJSOQEH2VVdND v0Hm6DQ/GaqOq3/2fpePd9pANjIBgYKvp1107fkkU2djRblc+Iliozf9lcYEoreoLZZh dihomCtwvfUQarwQC86SqLhKsRE13AvM4kbq3wYx/SpfS8O5jMQPfN0fakmj6CKIEmuq ZavQ== X-Gm-Message-State: AOAM531uxEIY5gXYSBqQlxjmb2wj6d6HEZpNhigHhZh/P57G3sKpHcbj pFVkgjPBX3L3gmDkyOySAwF6a/TGwwDCG8dbIPo= X-Google-Smtp-Source: ABdhPJzmYPvXM9RWCUymx2fmT6XYvMdDUf+zcWOlCXeZkIj/kr5dHvdo+Ck/htSQXEJKOuhc1Jb/2qXOuKuE30PXwag= X-Received: by 2002:a19:ad41:: with SMTP id s1mr16660851lfd.191.1596007442539; Wed, 29 Jul 2020 00:24:02 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 29 Jul 2020 09:23:46 +0200 Message-ID: To: tyson andre Cc: Joe Ferguson , PHP Developers Mailing List Content-Type: multipart/alternative; boundary="000000000000abe6ac05ab8f70ba" Subject: Re: [PHP-DEV] [RFC] [Discussion] Shorter Attribute Syntax Change From: nikita.ppv@gmail.com (Nikita Popov) --000000000000abe6ac05ab8f70ba Content-Type: text/plain; charset="UTF-8" On Wed, Jul 29, 2020 at 2:21 AM tyson andre wrote: > Hi internals, > > For #[, my main objection is the various ways this can change the lexing > in a way that is impractical to (efficiently) backfill, > and that the proposed patch doesn't address the fact that the syntax may > change the syntax of php 7 code in unexpected ways. > > This syntax would help phpcs with easy examples **in the short term**, > when attributes are on a single line, > but would make more complicated refactorings buggy and error-prone unless > phpcbf was run in the same major version. > When attributes span multiple lines, the lexing is completely different > for `#[]`. > For example, the below syntax would yield false in php 7, but a generator > in php 8. > (There's precedent at least - the lexing of heredocs changed in php 7.3 or > 7.4) > That's an interesting point. Emulating #[] lexing on older versions will definitely be a challenge for PHP-Parser. I don't think we should make concerns of external tooling hold us back too much, but the phpcs argument really doesn't hold water. Regards, Nikita > ``` > // Aside: This code snippet seems to have an assert failure in the lexer > with the patch in the RFC > // Zend/zend_compile.c:1794: zendlex: Assertion > `!(executor_globals.exception) || ret == T_ERROR' failed. > function generator() { > yield #[MyCustomAttribute(' > false; > // ']function() {}; > } > ``` > > And another example which would cause problems for phpcs in php 7 - the > comment syntax can cause code to be treated as inline html instead of php > tokens. > > ``` > // This example echoes the rest of the source code in php 7 > // and echoes "Test" in php 8. > #[DeprecationReason('reason: ')] > function main() {} > const APP_SECRET = 'app-secret'; > echo "Test\n"; > ``` > > I'd posted another example in https://externals.io/message/111101#111133 > > One way I'd thought of to avoid this ambiguity would be to assert in PHP > 8.0 with an E_COMPILE_ERROR (or E_COMPILE_WARNING) that: > 1. All tokens of the #[...] annotation are on the same line > 2. No non-whitespace token follows the ] on the same line. > It may be permissible to allow other `//` comments or multiple > attributes after it on the same line, though. > 3. No `?>` substrings within the rest of the line after #[, maybe > > Although I'm not sure if others are actually concerned about this > ambiguity and these are really artificial examples for code. > > As for `<<`, I'm assuming people may have meant `yield <> function() > {};`, > but `yield` already has a precedence and didn't have issues - otherwise > `yield+2;` could be adding 2 to the result of a yield. > (It's unambiguously `yield(+2);` right now). > I forget how it'd be parsed, but it wouldn't be ambiguous. > > As for `@@`, all of its known issues seem to have been resolved, > and there is still the potential for future issues, but I still prefer it > over the `#[` implementation in that patch. > > P.S. I'd like to note that > 1. A lot more discussion has occurred since the initial vote. > 2. Since `@@` was obviously passing at the time, fewer voters would put > much thought into detailed tradeoffs of `#[` > 3. I haven't seen those specific drawbacks to `#[` of potentially > significantly changing lexing (not just losing tokens) mentioned, > but the shorter attributes syntax RFC did seem to mention params were > commented out. > > One idea I'd have on voting would be to have the exact same 3-way vote, > again, and pick the attribute syntax with the same ranked choice procedure. > I assume proponents of `#[` would have similar objections if an RFC with a > two-way vote for `<<>>` and `@@` was started first. > > Regards, > - Tyson > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --000000000000abe6ac05ab8f70ba--