Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108179 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50803 invoked from network); 17 Jan 2020 15:13:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Jan 2020 15:13:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A30BA180540 for ; Fri, 17 Jan 2020 05:21:18 -0800 (PST) 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 ; Fri, 17 Jan 2020 05:21:17 -0800 (PST) Received: by mail-lj1-f179.google.com with SMTP id r19so26456789ljg.3 for ; Fri, 17 Jan 2020 05:21:17 -0800 (PST) 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=TcRprgraEWJs1Z2gs5k1qj2t0RlKXjsbHGNwaJcXLoM=; b=nooHg52kPlFjwgQIpJCaQ3frUrZ1CKPc6tGiOmo2Rx9LOKESyzwS3VLS/IK4nF6tuP p96bfUhPGu8QrEAGNZnkW4yCHbYvLqw3AToiUn+bvUsZCnaplEpO5kH89GWtaEWHmo/e 2WHHk9EivNH+v5QAZDnL2Ojx8iXd4Y27HAa8SDpEPIuiKfcmt6F4NAh96wgRnrQySM7P bf8cqPgbkypiQDyGwShwkiz1UQHUbruFVwTCVayfJ9dplZPUy0PI/iokc+7Thyj0fB9V yHw4c1fe7/UyfSkfbv391zmLvld/UHQXJtVSHrPAyp9qxqJqoJ1H9i8C/1Cd4hwVLqRF FzQg== 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=TcRprgraEWJs1Z2gs5k1qj2t0RlKXjsbHGNwaJcXLoM=; b=HsU+BRK1gM4IkX4znRHyF02iJ02TcA6vLFoeQCM0P09WVn3ncpMOkhKiA2gqFlKFoY fBPyS6iDMxTlr2CAMXwqXSNsr7LoiT/P6OxD5U7HcJO8WYbnEWf5QWNNLQL8r/s+/ksK ADWp7tpbfFFNCGfm9OXaHi+C/l6vcVA34KXanOljWo/G3KKUlNbgo73TZfLN1dHJvRVu LJuaRDVvWy1qwfBCt370BuxXZPmiPni2ZYWT9Um3118gHqecdPFsLVTlx58b979Vpywg 7ge+j81w7lqiv5AfXQ35SWJxdr9vIeqVzZPR+gdKtrNWd7kMlkZGJc+H9eJNpfRK9Eiu vkog== X-Gm-Message-State: APjAAAWBM7nzDfu7sZX2vaqt5cEw24eJc3Up1MFthuAS4bpsBOi1ounL S31JbV1sQNlcJPXCVWTNTy6m9dvaSoW5lvuBg6I= X-Google-Smtp-Source: APXvYqziwJp7ivel+KtB3+W4sFGuNJrDJ7oQ1CLqTMJEfQE1NHuNGkdcbicQkGm1rjDebPKg6Y7sDX/Sm3uAEXs3+/U= X-Received: by 2002:a2e:7a13:: with SMTP id v19mr5618937ljc.43.1579267275645; Fri, 17 Jan 2020 05:21:15 -0800 (PST) MIME-Version: 1.0 References: <629789F9-8E61-43DB-B186-75779A8372E7@gmail.com> In-Reply-To: <629789F9-8E61-43DB-B186-75779A8372E7@gmail.com> Date: Fri, 17 Jan 2020 14:20:58 +0100 Message-ID: To: Claude Pache Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000f86a37059c55d0eb" Subject: Re: [PHP-DEV] [RFC] Variable syntax tweaks From: nikita.ppv@gmail.com (Nikita Popov) --000000000000f86a37059c55d0eb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 16, 2020 at 10:12 AM Claude Pache wrote: > > > > Le 7 janv. 2020 =C3=A0 11:23, Nikita Popov a =C3= =A9crit : > > > > Hi internals, > > > > I'd like to propose a small RFC, which addresses a few minor issues tha= t > > have not been handled by the original "uniform variable syntax" RFC: > > > > https://wiki.php.net/rfc/variable_syntax_tweaks > > > > This is all about edge cases of edge cases, of course. I think the only > > part here that is not entirely straightforward and may need some > discussion > > is how arbitrary expression support for instanceof should be handled. > > > > Regards, > > Nikita > > Hi, > > The RFC looks good for me, except for one point. Concerning the arbitrary > expression support for `new` and `instanceof`, I strongly think that the > most consistant choice for delimiters among =E2=80=9C(...)=E2=80=9D (pare= ntheses) and > =E2=80=9C{...}=E2=80=9D (braces) is not braces =E2=80=9C{...}=E2=80=9D, = but parentheses =E2=80=9C(...)=E2=80=9D. Your > argument is based on the position of the expression (RHS vs LHS). My > argument is based on the type (in a broad sense) of the thing that the > expression is supposed to represent. > > The braces are used when the expression is expected to represent: > > * a variable name: `${...}` > * a property name: `$x->{...}` =E2=80=94 `X::${...}` > * a method name: `$x->{...}()` =E2=80=94 `X::{...}()` > > In all those cases, the expression inside `{...}` must evaluate to a > string, and will be interpreted as a name. > > On the other hand, the parentheses are used when the expression is > expected to represent: > > * an array: `(...)["key"]` > * an object: `(...)->prop` =E2=80=94 `(....)->meth()` =E2=80=94 `clone (.= ..)` > * a function: `(...)($arg)` > * a class: `(...)::KONST` =E2=80=94 `(...)::${statProp}` =E2=80=94 `(...= )::${statMeth}()` > > In the first two cases, the expected entity, =E2=80=9Carray=E2=80=9D or = =E2=80=9Cobject=E2=80=9D, is a > first-class value, and the expression inside `(...)` will be interpreted = as > such. > > The last two cases are more interesting. For the =E2=80=9Dfunction=E2=80= =9D cases, it can > be: > * a string representing a function (interpreted as the fully qualified > name of a function); > * an array `[ $obj, "meth" ]`, `[ "klass", "meth" ]` or a string > "klass::meth" representing a method; > * a closure or another object implementing the magic __invoke() method. > > For the =E2=80=9Cclass=E2=80=9D case, it can be: > * a string representing a class (interpreted as the fully qualified name > of a class); > * an instance of a class. > > In those cases, the expected entity may be a first-class citizen (a > closure, an instance of a class), or an entity that, although not a > first-class citizen, is unambiguously(*) represented by some other > first-class value (a function by their fully qualified name, etc.) and > could have been reasonably designed as first-class citizen (and indeed, a > function may be replaced with a Closure object with the same functionalit= y). > > (*) (For the sake of not complicating the argument, I=E2=80=99m ignoring = callables > whose meaning depends on context such as `["self", "foo"]`.) > > You rightly noted that the braces `{...}` are used exclusively on the RHS= ; > that follows from their meaning: a bare name has no significance out of > context, where the context is whether it is a function name, or whether i= t > is a property/method name and of which object/class the property/method i= s, > or etc. That context is more naturally provided before (at the left of) t= he > name. > > On the other hand the parentheses `(...)` are often used on the LHS: this > place is the natural place for an entity (an object, a class, etc.) that > don=E2=80=99t need more context to be well-defined, and that serves as ta= rget for > some action (call the function, look up the property of an object, etc.) > However, although the entity is often placed at LHS, this is not > systematic; consider f.e. `clone $obj`, which is quite similar to `new > klass`. > Thanks for the feedback Claude. I think you make a compelling case, and have updated the RFC to use "new (expr)" and "$x instanceof (expr)" syntax instead. Regards, Nikita --000000000000f86a37059c55d0eb--