Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66229 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55470 invoked from network); 26 Feb 2013 06:42:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2013 06:42:03 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain zend.com does not designate 209.85.216.48 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.216.48 mail-qa0-f48.google.com Received: from [209.85.216.48] ([209.85.216.48:40699] helo=mail-qa0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/11-44936-9395C215 for ; Tue, 26 Feb 2013 01:42:02 -0500 Received: by mail-qa0-f48.google.com with SMTP id j8so2205944qah.0 for ; Mon, 25 Feb 2013 22:41:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-gm-message-state; bh=74l8WhuVTEthVRWlpEWB2yUp0hsgq5k+4OoSBVt57Fs=; b=Fs/tBCNbybyh4wNDuzVK/eSx37H9XaJTQfVHaBblTWG7NpBQKLd2EDCc+3u3ksLWVe SpVB6s7Ay2843fQPNuvBnNemZPK42fTHUCgO/Ix9ftes4Z++iXZWwf0dWsyiKcPLDyCZ libI0Ubo5xAAxVXsnh4/98yLScv1UCf+JACudsnCxtxXhinampVM8ruV0kzUmxmMV8D9 3hP/74NvC8ilSrFILD2w5hTy+RCxLlheWLKjRvHt3kk3FCASP8gtCx1eq4vyWK/bqAPP FUvtFkXmLMS7oAtCcNUkeTM3cLHdHeD1xRRMKGAjTYDh38QqJFuG38N652yatqKMT3je 77xQ== MIME-Version: 1.0 X-Received: by 10.224.178.4 with SMTP id bk4mr220485qab.70.1361860919170; Mon, 25 Feb 2013 22:41:59 -0800 (PST) Received: by 10.49.106.201 with HTTP; Mon, 25 Feb 2013 22:41:59 -0800 (PST) In-Reply-To: References: Date: Tue, 26 Feb 2013 09:41:59 +0300 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary=20cf302ef94a5232ba04d69af462 X-Gm-Message-State: ALoCoQnF/5uu3La6cXcq8XH5Wq+CHuSigE6UI00F8MCjsoFsMEFRtUmBlpwFaiThI4Pr8mHHOP0TsvjEs5J1xBQKsvCe1dw/VFoJEChg923JmEviNzUvbnc+HIuy3eMudPfKpMLaW99G Subject: Re: [PHP-DEV] Allow (...)->foo() expressions not only for `new` From: dmitry@zend.com (Dmitry Stogov) --20cf302ef94a5232ba04d69af462 Content-Type: text/plain; charset=UTF-8 Hi Nikita, I like the idea. But note, that it may cause some unexpected behaviour and bugs. I didn't test the patch I just guess it on my previous experience introducing similar features. - usage expression in write context (e.g. passing constant by reference) function foo(&$foo) {} foo("abc"[0]); - destruction of temporary result ($a . $b)[4]; // if ($a.$b) is destroyed? - in some cases destruction of temporary result may cause destruction of final result ((object)(array("a"=>"b")))->a = "c"; // temporary object may be destroyed before assignment All these edge cases must be carefully analyzed. I like the current patch, and in case the edge cases won't require many hacks, I'm all for it. Thanks. Dmitry. On Mon, Feb 25, 2013 at 8:14 PM, 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 > --20cf302ef94a5232ba04d69af462--