Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66197 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49937 invoked from network); 25 Feb 2013 16:14:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2013 16:14:31 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:40002] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BA/0C-10787-6ED8B215 for ; Mon, 25 Feb 2013 11:14:31 -0500 Received: by mail-ob0-f170.google.com with SMTP id wc20so3060207obb.1 for ; Mon, 25 Feb 2013 08:14:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=2d4aV+xDsVSnk9S84vrgsycy6XS3KukBPSdWhGT6shs=; b=TbVSpo04Xbjq00zU0dyNzdJAkFqRUXIJbFP/JKlMI3C+eDUoM2l19/41ID5Lw/rq4R CkxF4UInGehwdlK1/mx4MWSK3lejty2jjSqTPSfdc7qSNXykzbliaN6Tw3U6tB/b010G lC3NKSwYu+vJh4QGLwU6U7kVtal2+hij3UuVaz1ef7+3CQUzGiHPkvvs3GugZykLNG/G Zr1knxmSMRnXY0FiqRpy+3vOaL0m1Af0O6QPKxWWmWHAnESk3nCZAGONItsCh6ZnYe5/ UxzEMQa+g/3NtyW1MIscYeuhF2KypLds9H1z+5lQFa9ZpDt52/7if+ZFT67rUoBQ+wv2 f4OQ== MIME-Version: 1.0 X-Received: by 10.60.10.102 with SMTP id h6mr8065169oeb.14.1361808867930; Mon, 25 Feb 2013 08:14:27 -0800 (PST) Received: by 10.182.49.136 with HTTP; Mon, 25 Feb 2013 08:14:27 -0800 (PST) Date: Mon, 25 Feb 2013 17:14:27 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=e89a8fb1f4aed66c5c04d68ed532 Subject: Allow (...)->foo() expressions not only for `new` From: nikita.ppv@gmail.com (Nikita Popov) --e89a8fb1f4aed66c5c04d68ed532 Content-Type: text/plain; charset=ISO-8859-1 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 --e89a8fb1f4aed66c5c04d68ed532--