Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56691 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91110 invoked from network); 30 Nov 2011 19:51:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Nov 2011 19:51:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=ralph@ralphschindler.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ralph@ralphschindler.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain ralphschindler.com from 209.85.160.170 cause and error) X-PHP-List-Original-Sender: ralph@ralphschindler.com X-Host-Fingerprint: 209.85.160.170 mail-gy0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:63084] helo=mail-gy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 16/9D-17272-64986DE4 for ; Wed, 30 Nov 2011 14:51:34 -0500 Received: by ghbg16 with SMTP id g16so1182517ghb.29 for ; Wed, 30 Nov 2011 11:51:31 -0800 (PST) Received: by 10.236.146.4 with SMTP id q4mr6172061yhj.105.1322682691417; Wed, 30 Nov 2011 11:51:31 -0800 (PST) Received: from ralph-mac.local (ip174-73-14-247.no.no.cox.net. [174.73.14.247]) by mx.google.com with ESMTPS id m33sm8254202ann.4.2011.11.30.11.51.29 (version=SSLv3 cipher=OTHER); Wed, 30 Nov 2011 11:51:30 -0800 (PST) Message-ID: <4ED68940.3050502@ralphschindler.com> Date: Wed, 30 Nov 2011 13:51:28 -0600 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: Nikita Popov CC: internals References: <4ED6713D.2050009@ralphschindler.com> <4ED67DCB.5090102@ralphschindler.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] 5.4's New De-referencing plus assignment From: ralph@ralphschindler.com (Ralph Schindler) Ironically, quite the opposite is something I find useful: ($foo = new MyComponent($bar))->configure($options); In a single line, instantiate and configure (via an API call) an object. The return of configure() is not important to me, but the brevity of that workflow, and the result of "new" is. -ralph On 11/30/11 1:13 PM, 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?" :)