Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56690 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89620 invoked from network); 30 Nov 2011 19:45:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Nov 2011 19:45:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=devis@oracolo.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=devis@oracolo.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain oracolo.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: devis@oracolo.com X-Host-Fingerprint: 209.85.215.42 mail-lpp01m010-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:49609] helo=mail-lpp01m010-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 95/4D-17272-5F786DE4 for ; Wed, 30 Nov 2011 14:45:58 -0500 Received: by lami14 with SMTP id i14so399688lam.29 for ; Wed, 30 Nov 2011 11:45:53 -0800 (PST) Received: by 10.152.132.72 with SMTP id os8mr2555481lab.4.1322682353706; Wed, 30 Nov 2011 11:45:53 -0800 (PST) MIME-Version: 1.0 Sender: devis@oracolo.com Received: by 10.152.21.40 with HTTP; Wed, 30 Nov 2011 11:45:12 -0800 (PST) In-Reply-To: References: <4ED6713D.2050009@ralphschindler.com> <4ED67DCB.5090102@ralphschindler.com> Date: Wed, 30 Nov 2011 19:45:12 +0000 X-Google-Sender-Auth: JXN3e5qGqa3aVCvxvpovi6r4BN0 Message-ID: To: Nikita Popov Cc: Ralph Schindler , internals Content-Type: multipart/alternative; boundary=f46d04308560d7e58604b2f8fb1b Subject: Re: [PHP-DEV] 5.4's New De-referencing plus assignment From: devis@lucato.it --f46d04308560d7e58604b2f8fb1b Content-Type: text/plain; charset=UTF-8 Hi, personally I would find the proposed syntax very useful, similarly to the following one that is already implemented: if ($value = foo()) return $value instead of $value = foo(); if ($value) return $value; Regards, Devis On 30 November 2011 19:13, Nikita Popov wrote: > To me the main problem here is that $bar = ($foo = new Foo)->bar() > simply doesn't make much sense. It is equivalent to: > $foo = new Foo; > $bar = $foo->bar(); > Which is much cleaner and easier to understand. > > The plain (new Foo)->bar() syntax *is* useful for cases like (new > ReflectionClass($class))->implementsInterface('Foo'), where you need > only one single bit of information from a class. > > Nikita > > On Wed, Nov 30, 2011 at 8:02 PM, Ralph Schindler > wrote: > > Nikita, > > > > You're completely right about the expanded expressions, but I'm not sure > its > > an edge-case per-se. > > > > The problem with the current syntax is that the resultant of the 'new' > > operation is lost UNLESS your chained method returns $this - which IMO > makes > > it about as 1/2 as useful as it really could be. > > > > In the case of "new" though, the resultant is always an object, it seems > > like it should be permissible to change the parser to allow for variable > > assignment of the target object. > > > > I think for people just trying out this new behavior (by seeing it in the > > release notes as (new Foo)->bar()), the next logical thing is to try this > > syntax: > > > > ($foo = new Foo)->bar() > > > > // OR in bison > > '(' variable '=' new_expr ')' > > > > I did it, and I see other people doing it too. So I guess the question > is... > > "how edge case is this edge case?" :) > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d04308560d7e58604b2f8fb1b--