Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66199 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52877 invoked from network); 25 Feb 2013 16:20:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2013 16:20:27 -0000 Authentication-Results: pb1.pair.com header.from=jonwage@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jonwage@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.177 as permitted sender) X-PHP-List-Original-Sender: jonwage@gmail.com X-Host-Fingerprint: 209.85.217.177 mail-lb0-f177.google.com Received: from [209.85.217.177] ([209.85.217.177:34722] helo=mail-lb0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 64/BC-10787-94F8B215 for ; Mon, 25 Feb 2013 11:20:26 -0500 Received: by mail-lb0-f177.google.com with SMTP id go11so2381864lbb.36 for ; Mon, 25 Feb 2013 08:20:22 -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=uFUYHy3PpDe6yqoTIJNavxUa2y6fIuCQnyk+FdV7J8U=; b=Z0T14k0Q06qFyPTx0mbZfLtj9repUXrJnUp0NHU6ma0hh5tBgjtmOimDWDp4zCeYj9 kPusVnM9I5n5OWNzPnux3JTJXbDLtQpt24ddh02885Hm6QjZU0/c8C/0cFW+6X0jg7Be 32aC+SJUi6tr4LDXWooCXkPeNGuRrNWD8SymUBk0FEQ85tSWEQgEA8T4IR50UDzTGlgU PZxfrlKYqSzsSQWdxKmps7R0bSqYbNjRyTVcQhgZo5lb9RgavcgYbyZHhMk2hUTGvADU rrkCsN/ZPsWuz6Ol/r3eg7kVEa01VR/tm/vRJ6xB53vw7AhM4uUP6iJQXxrjj8/9zFI0 5d1A== X-Received: by 10.152.104.80 with SMTP id gc16mr10422307lab.49.1361809222277; Mon, 25 Feb 2013 08:20:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.112.80.166 with HTTP; Mon, 25 Feb 2013 08:20:01 -0800 (PST) In-Reply-To: References: Date: Mon, 25 Feb 2013 10:20:01 -0600 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary=f46d040714d5f2ae9304d68eeaf4 Subject: Re: [PHP-DEV] Allow (...)->foo() expressions not only for `new` From: jonwage@gmail.com (Jonathan Wage) --f46d040714d5f2ae9304d68eeaf4 Content-Type: text/plain; charset=ISO-8859-1 It makes sense to me. +1 for making the syntax more consistent and natural. - Jon On Mon, Feb 25, 2013 at 10:14 AM, Nikita Popov wrote: > 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(). > > 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 > -- Connect with me on *http://twitter.com/jwage* and http://about.me/jwage to keep in touch. Join OpenSky today: http://osky.co/l6a75g --f46d040714d5f2ae9304d68eeaf4--