Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101811 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90441 invoked from network); 8 Feb 2018 18:45:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2018 18:45:24 -0000 Received: from [127.0.0.1] ([127.0.0.1:27345]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id E6/30-21403-4CA9C7A5 for ; Thu, 08 Feb 2018 13:45:24 -0500 Authentication-Results: pb1.pair.com smtp.mail=mcmuffinmcguffin@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=mcmuffinmcguffin@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.173 as permitted sender) X-PHP-List-Original-Sender: mcmuffinmcguffin@gmail.com X-Host-Fingerprint: 209.85.223.173 mail-io0-f173.google.com Received: from [209.85.223.173] ([209.85.223.173:37466] helo=mail-io0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 94/30-21403-0399C7A5 for ; Thu, 08 Feb 2018 13:38:40 -0500 Received: by mail-io0-f173.google.com with SMTP id f89so6834801ioj.4 for ; Thu, 08 Feb 2018 10:38:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=A9vRKdayQWOH7/klOuWXYJAqsnIDrybUN2rOwRH4D4E=; b=R6CbAwsJ/6HZhdfv8clHkieRG/PBvDZLbdHKJgGn95vPkan3u6RiH5AS1oFW51wqvF fTwDriwGcTSQOSj9EP7KYVgp3YG40twkLWxS332Ev+SZXluMYcjmPcjw956OGQiaEkdX wuH8V78ankO8xiKWy76yI3r0HwV+jql9C8a5lr/VqkqNSdcMdQhcn/4U0RCM4kabxtBT TUf+f5yTjdGbk4DVAmj9CVLqoTZ7PK4c+IW7Wox1g3+a1kmAWYi0nTUPcNSodsCtq8qu A4GTpHFQgOI60k9v9QiE0ZGuGA96Uz39+yxN9v4aK1zn2ijHN8Uc4NlMxfK+wGS/tQkV Ir/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=A9vRKdayQWOH7/klOuWXYJAqsnIDrybUN2rOwRH4D4E=; b=bLp8KNjoZjnNeq55cYey9FQ+eLZUaFZ1m+EL1fzOOxY5342EZsVBmY9LyB2OmlOdo7 zJcbXSow9xMoTL8ig4dlF+2qf5SeqqT/b9KH//JpYxeuhFkqbTROgF/91ezu2V7JgQzM 6XhvY8C5WfhrEwtobQSqLGzXbcEOT6zFAwNXfVIgDPrQz3QwUSTf2M9jeXr8XGJMbh3c 8HvMSSECYHCyT1Dzck2qZws1BVjGUvKzDpqWwlHr0rFsJLE8WHUmSbf0DCzK8HRSuLW3 3hxRLnaW11ims7rx7hOaJEU87V4NgM9+AwzGTrGNBnINC+JZtcWBrO1h3LkgVMLWz2mT 5kXg== X-Gm-Message-State: APf1xPD8njFZ78ffBALEWhFxXHy3AXmpjvy9f5Z44I0sOFTc0z/v4lNM Z1nJjbC3B38jg3TnSsQ3owQmgkN70aPDHRUQX6bVEqbR X-Google-Smtp-Source: AH8x226eI7QdiZx+08hPLBipnTMal8z9269+w3PaOEntvjuB30UjZt/TNo03eJkI/qnQAsI95uUoDoRmPbpsVnIe1z8= X-Received: by 10.107.129.99 with SMTP id c96mr172520iod.159.1518115116704; Thu, 08 Feb 2018 10:38:36 -0800 (PST) MIME-Version: 1.0 Received: by 10.79.206.17 with HTTP; Thu, 8 Feb 2018 10:38:36 -0800 (PST) Date: Thu, 8 Feb 2018 21:38:36 +0300 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="001a113f39e44267500564b7b8fb" Subject: Suggested change: change priority of new and -> From: mcmuffinmcguffin@gmail.com (Mcmuffin Mcguffin) --001a113f39e44267500564b7b8fb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, It's a common idiom in object-oriented languages to create an object and then immediately call a method on it, such as (in C# or Java): new DateTime ().ToString () However, PHP grammar does not work this way. You have to put an additional round of parentheses around new clause, such as: (new DateTime ())->format ('Y-m-d') This is rather clunky for such a common scenario (you usually have to walk all the way back to the beginning of the expression to fix it). I have a pattern of using static factories in place of constructor just to avoid extra parentheses. Besides, the issue is relatively easy to fix. I've done and tested a change for grammar in this area. It's a slight adjustment to definition of dereferencable: dereferencable: > variable { $$ =3D $1; } > | '(' expr ')' { $$ =3D $2; } > * | new_expr { $$ =3D $1; }* > | dereferencable_scalar { $$ =3D $1; } > ; > There was a problem with shift/reduces though. PHP has a level of complexity in new expression which other languages don't. It's variable class instantiation, such as: new $class (arguments) Expressions in place of $class can be rather complex, though I don't think they really need to be. For example, such stuff is allowed: new $var[0]->prop (arguments) =E2=80=94 which seems redundant and confusing. My fix to the problem was to= force parentheses around complex expressions such as above: new ($var[0]->prop) (arguments) =E2=80=94 while keeping simple cases of "new $class (arguments)" without ch= ange. Yes, this moves parentheses from one place to another (and occasionally breaks the old code) but frequency wise I think it's an improvement. What do you think? Jaroslav Wegner --001a113f39e44267500564b7b8fb--