Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101813 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5305 invoked from network); 8 Feb 2018 22:35:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2018 22:35:31 -0000 Authentication-Results: pb1.pair.com header.from=hkdobrev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=hkdobrev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.194 as permitted sender) X-PHP-List-Original-Sender: hkdobrev@gmail.com X-Host-Fingerprint: 209.85.220.194 mail-qk0-f194.google.com Received: from [209.85.220.194] ([209.85.220.194:46486] helo=mail-qk0-f194.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2D/82-21403-3B0DC7A5 for ; Thu, 08 Feb 2018 17:35:31 -0500 Received: by mail-qk0-f194.google.com with SMTP id d144so902517qkg.13 for ; Thu, 08 Feb 2018 14:35:30 -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=bCeIz2OL9R2SdZgPhwnCav2vclhlTDyptlQHLtTib4U=; b=O4cOKY0jQa/xtBzy4a4Ct/IEbugE2rGFMuaYfpxssX7Uc+jLcJaZCacWqrSAScwdju 6ahStmcJcGOJgGP4/PhaIS8624327JJjRxd8kmXMJe9b6JEuXBhoEGB8knrEUfM/KtSE ZnT0zfMGWWomyKtxCE/rnskvCzuC3VDJkiousLdZxxpi7W6qL3M3SkxEDo6qZgOqsGiI BtFfPYDr0I0XDAUmV9bEe0XPmJgNZcD+7KhKf0H/jELiAH7gByRp69VJeMLcYDiC/UlT UVfXXuCCxX/r36xVdWKcVt5ZKzQ26My8J1MUh5PDiBWuf+U9dGMmmHj0j0+MIhMxfHQV bLUg== 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=bCeIz2OL9R2SdZgPhwnCav2vclhlTDyptlQHLtTib4U=; b=GBAPVaGCYIwv6xhR/yTBkmcL8IJjYe1krAKfh+JHUlUHMMXZiRiomZXdIupy3BWqtE vtbTm7YtsU8qSsHLhKEquCrnJ9kES5s0Jcn4V2cdpjjIA1D6lNwEBZ8pMBkQa2Co3EX5 GkbG9kMDPyhjPxSiDgzOmJrmW+lf+kvDyR5FwSYDWT+FZRbMqjn4E+CyJsttlsFgfiho Ni0OtwsFkOZagU+gIUKXhEz+dVza1BdGAmSgaciwvatHuOyEMIXY0ZKlXPRLGdSVs+QY reefSbBlByHXLv5wogMwlr4YiFTGbzaHbL2EVqDL69KXlC+Ahtw53eyYUTn4tU2R/k1N 6Asw== X-Gm-Message-State: APf1xPA7rLtw7FTvwFKHcLP1cZesXfwb45m+E1U8omEIejfKv6ezn9oN kelM9lkAOFg7ttUVcIv7jQeKPac/l+r4B4wzGzA= X-Google-Smtp-Source: AH8x2275KVvC6JNEKwSNsccbvqBa71SFHqmy9CeIOCQu0ugWkasXb5cFZ5v+0ASJW7RiKS3Ar7Om//X1zuqgQS3ghEI= X-Received: by 10.55.191.69 with SMTP id p66mr910497qkf.315.1518129327667; Thu, 08 Feb 2018 14:35:27 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 08 Feb 2018 22:35:16 +0000 Message-ID: To: Mcmuffin Mcguffin Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="94eb2c043d424c81990564bb07ca" Subject: Re: [PHP-DEV] Suggested change: change priority of new and -> From: hkdobrev@gmail.com (Haralan Dobrev) --94eb2c043d424c81990564bb07ca Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I really like the proposal and it's definitely improving more common modern use cases. However, I understand why the precedence is like that now in PHP to begin with and so I think this should target PHP 8. This change would be a bit similar to other weird use cases of variables which were changed with PHP 7. Best, Harry On Thu, 8 Feb 2018 at 20:45 Mcmuffin Mcguffin wrote: > 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 additiona= l > 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 wal= k > 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 don= e > 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 thin= k > 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 = change. > 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 > --=20 Haralan Dobrev CTO @ Clippings.com https://hkdobrev.com --94eb2c043d424c81990564bb07ca--