Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66241 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88690 invoked from network); 26 Feb 2013 12:36:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2013 12:36:14 -0000 Authentication-Results: pb1.pair.com header.from=krebs.seb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:35070] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 57/11-16132-B3CAC215 for ; Tue, 26 Feb 2013 07:36:12 -0500 Received: by mail-wi0-f180.google.com with SMTP id hi8so4566466wib.7 for ; Tue, 26 Feb 2013 04:36:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=7DdBqUcYgLQJECWYAFbUSP0YGPkY0I4DTltBLg0fMZQ=; b=kwvc8O/R8py9aKyRthpMHCN3zFFzoTcuPQDSCwcwKAu869jQq0GXHZ37usPuw7KG7G rN20luD4psULI17EM6zFekGhZ+R/lMkVqS8C0y8iZO07TPL6yqfqLAi40fSURBgg8qeG aApZxfLOLIEc96nLrLIUM8lDYsVl3RqtcVOLCyqUxdaBB9RNR6nmy89jOpG1QWIsbx5J 5Y1mVUb1t8265WKav8wER9XeS639w2CVPH6958KeMeLGpUMMgz/8KombBnITtS7u12yt 9F4MJp2a1u1CEn1lfZXQZCYUAiZS23DvUoYXxo1n+9VN5PHqtEPsUtlgMXi96PNVU+OM wYsA== X-Received: by 10.180.80.35 with SMTP id o3mr19215698wix.9.1361882168834; Tue, 26 Feb 2013 04:36:08 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.98.197 with HTTP; Tue, 26 Feb 2013 04:35:47 -0800 (PST) In-Reply-To: References: Date: Tue, 26 Feb 2013 13:35:47 +0100 Message-ID: To: Lazare Inepologlou Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary=f46d044287f2e66c3b04d69fe673 Subject: Re: [PHP-DEV] Allow (...)->foo() expressions not only for `new` From: krebs.seb@gmail.com (Sebastian Krebs) --f46d044287f2e66c3b04d69fe673 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2013/2/26 Lazare Inepologlou > Hello Nikita, > > 2013/2/25 Nikita Popov > > > Hi internals! > > > > PHP 5.4 added support for expressions of the kind (new Foo)->bar(), (ne= w > > Foo)->bar and (new Foo)['bar']. > > > > > I guess it must have been discussed, but Is there any technical reason or > conflict that prevents us from having something like new Foo->bar(), > without the extra parenthesis? > It could mean "new (Foo->bar())", which in this case is invalid, but there are other cases, where this problem is more obvious if ($foo) { $bar =3D 'Classname'; } else { $bar =3D new BarClass; } new $bar->baz(); // "(new $bar)->baz()" or "new ($bar->baz())"? > > > > > > I'd like to extend this support to any expression instead of just new. > > > > Why should be do this? Because it's just an arbitrary restriction. > Removing > > it would for example allow clone calls in the parens, so you could do > > something like (clone $date)->modify('...'). Which - you may have alrea= dy > > noticed this - is more or less a replacement for the DateTimeImmutable > > class that was added for 5.5 (with the nice benefit of being fully > > compatible and not being an object oriented abomination :) That's just > one > > example, but I think there are a lot more (especially if you also > consider > > that it allows array dereferencing too). One further use that is of > > interest to me personally is for https://github.com/nikic/scalar_object= s > , > > so I can do calls like ("foo")->bar(). > > > > A nice side benefit from this is that it removes a shift/reduce conflic= t > > from the parser. > > > > The patch for the change can be found here: > > https://github.com/php/php-src/pull/291/files. It's a very simple patch= , > > it > > basically just changes one parser rule and adjusts the allowed opp type= s > > for some opcodes. The rest is just the vm regeneration for the new op > > types. > > > > I hope that this change is trivial enough to not require dragging it > > through the whole RFC process. If there are no objections I'd commit it > > sometime soon. > > > > Thoughts? > > Nikita > > > > > Lazare INEPOLOGLOU > Ing=E9nieur Logiciel > --=20 github.com/KingCrunch --f46d044287f2e66c3b04d69fe673--