Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66225 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16750 invoked from network); 25 Feb 2013 23:08:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2013 23:08:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=jelle.zijlstra@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jelle.zijlstra@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.46 as permitted sender) X-PHP-List-Original-Sender: jelle.zijlstra@gmail.com X-Host-Fingerprint: 209.85.214.46 mail-bk0-f46.google.com Received: from [209.85.214.46] ([209.85.214.46:36221] helo=mail-bk0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3F/29-10787-BEEEB215 for ; Mon, 25 Feb 2013 18:08:28 -0500 Received: by mail-bk0-f46.google.com with SMTP id j5so1577206bkw.19 for ; Mon, 25 Feb 2013 15:08:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=na5wEw5H7uRzJXwLOBIzQhCLbowFzbfPLdlGy1guScU=; b=o/+oyku2g4HbR8BEWqypBoEVhgcraLO16UZ+5G4XTDVuzmVizNYALlwL22rRb3epcg lUJCTSMrz/PfbeAxGfMlZjgdq1h8bIIafB/aXXlCDE0J9ZCGKdg52sk3UIWxgt/AV4nB wKAs3aRtZzoXnhQ/bt8UJR1W9tg7HiUelo4HteKvxwAXphptGy6GPpbTCZeiAREUAwhm CHW4lvI71pjfFlSJ8lS4PlD27H42LyZP8oeHBb/FMtUa64mznCpivtBwh44nolFg4Zsa 99Hg5zT1cNM88gtER3o8buQ0zWII6EZEJJH1q09clw/3bzGKaCr+vIiGJs0UjysSiK4n h3kg== MIME-Version: 1.0 X-Received: by 10.204.149.87 with SMTP id s23mr5803258bkv.33.1361833704930; Mon, 25 Feb 2013 15:08:24 -0800 (PST) Received: by 10.204.13.211 with HTTP; Mon, 25 Feb 2013 15:08:24 -0800 (PST) In-Reply-To: References: Date: Mon, 25 Feb 2013 18:08:24 -0500 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary=0015175cae2e3a038f04d6949e51 Subject: Re: [PHP-DEV] Allow (...)->foo() expressions not only for `new` From: jelle.zijlstra@gmail.com (Jelle Zijlstra) --0015175cae2e3a038f04d6949e51 Content-Type: text/plain; charset=ISO-8859-1 2013/2/25 Nikita Popov > Hi internals! > > PHP 5.4 added support for expressions of the kind (new Foo)->bar(), (new > Foo)->bar and (new Foo)['bar']. > > 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 already > 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_objects, > so I can do calls like ("foo")->bar(). > > Out of curiosity, will the parser blow up if we remove the requirement for parentheses, so that things like "foo"->bar() would be possible? > A nice side benefit from this is that it removes a shift/reduce conflict > 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 types > 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 > --0015175cae2e3a038f04d6949e51--