Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56694 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96474 invoked from network); 30 Nov 2011 20:07:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Nov 2011 20:07:55 -0000 Authentication-Results: pb1.pair.com header.from=will.fitch@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=will.fitch@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.170 as permitted sender) X-PHP-List-Original-Sender: will.fitch@gmail.com X-Host-Fingerprint: 209.85.160.170 mail-gy0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:39745] helo=mail-gy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 11/00-30469-A1D86DE4 for ; Wed, 30 Nov 2011 15:07:54 -0500 Received: by ghbg16 with SMTP id g16so1201628ghb.29 for ; Wed, 30 Nov 2011 12:07:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=+ZF9PZE9Hu50r+S6FwtS9gff1ceu0cpgEkHRHI0x8wU=; b=bnQDUWP+PLq0FCF2YFMSh4HJwjDO6+l0771CdPI11PyDbOzUbZ1Gxjl2nkkihquC52 G/IM/w7QgV4KI8qumzH3Tf483twS1DBCDvhz4z4oYqDVV7RBcefpICCUrkwkGzh6/rc8 iIxTVSna1Ago8/o9UKCb0Dqs9HrEwJ62I+hBY= Received: by 10.236.155.170 with SMTP id j30mr6340687yhk.56.1322683202112; Wed, 30 Nov 2011 12:00:02 -0800 (PST) Received: from [192.168.1.68] ([68.64.144.221]) by mx.google.com with ESMTPS id f14sm8294823ani.8.2011.11.30.11.59.59 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 30 Nov 2011 12:00:00 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1251.1) Content-Type: text/plain; charset=us-ascii In-Reply-To: <00ea01ccaf9a$2ab7e160$8027a420$@alliantinternet.com> Date: Wed, 30 Nov 2011 14:59:57 -0500 Cc: "'Ralph Schindler'" , "'Nikita Popov'" , "'internals'" Content-Transfer-Encoding: quoted-printable Message-ID: References: <4ED6713D.2050009@ralphschindler.com> <4ED67DCB.5090102@ralphschindler.com> <4ED68940.3050502@alliantinternet.com> <00ea01ccaf9a$2ab7e160$8027a420$@alliantinternet.com> To: "Dmitri Snytkine" X-Mailer: Apple Mail (2.1251.1) Subject: Re: [PHP-DEV] 5.4's New De-referencing plus assignment From: will.fitch@gmail.com (Will Fitch) Again, back to my question of why not use: MyComponent::factory($bar, $option); =20 Depending on what ::factory does, it could then pass $option(s) to the = constructor or method getting your instance needed. On Nov 30, 2011, at 2:56 PM, Dmitri Snytkine wrote: > Just for such case I use factory methods in a class, so I can do this: > MyComponent::factory($bar)->configure($option) >=20 > A clean one-liner. >=20 > The static factory method just returns the object of class, your = standard > factory pattern. > Plus you may gain extra flexibility from using factory instead of = directly > calling new() >=20 > Dmitri Snytkine > Web Developer > Ultra Logistics, Inc. > Phone: (888) 220-4640 x 2097 > Fax: (888) 795-6642 > E-Mail: dsnytkine@ultralogistics.com > Web: www.ultralogistics.com >=20 > "A Top 100 Logistics I.T. Provider in 2011" >=20 >=20 > -----Original Message----- > From: Ralph Schindler [mailto:ralph@ralphschindler.com]=20 > Sent: Wednesday, November 30, 2011 2:51 PM > To: Nikita Popov > Cc: internals > Subject: Re: [PHP-DEV] 5.4's New De-referencing plus assignment >=20 > Ironically, quite the opposite is something I find useful: >=20 > ($foo =3D new MyComponent($bar))->configure($options); >=20 > In a single line, instantiate and configure (via an API call) an = object.=20 > The return of configure() is not important to me, but the brevity of=20= > that workflow, and the result of "new" is. >=20 > -ralph >=20 >=20 > On 11/30/11 1:13 PM, Nikita Popov wrote: >> To me the main problem here is that $bar =3D ($foo =3D new = Foo)->bar() >> simply doesn't make much sense. It is equivalent to: >> $foo =3D new Foo; >> $bar =3D $foo->bar(); >> Which is much cleaner and easier to understand. >>=20 >> 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. >>=20 >> Nikita >>=20 >> On Wed, Nov 30, 2011 at 8:02 PM, Ralph Schindler >> wrote: >>> Nikita, >>>=20 >>> You're completely right about the expanded expressions, but I'm not = sure > its >>> an edge-case per-se. >>>=20 >>> 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. >>>=20 >>> 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. >>>=20 >>> 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: >>>=20 >>> ($foo =3D new Foo)->bar() >>>=20 >>> // OR in bison >>> '(' variable '=3D' new_expr ')' >>>=20 >>> I did it, and I see other people doing it too. So I guess the = question > is... >>> "how edge case is this edge case?" :) >=20 >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20