Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50599 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61688 invoked from network); 26 Nov 2010 20:46:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Nov 2010 20:46:49 -0000 Authentication-Results: pb1.pair.com header.from=peter.e.lind@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=peter.e.lind@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: peter.e.lind@gmail.com X-Host-Fingerprint: 209.85.161.170 mail-gx0-f170.google.com Received: from [209.85.161.170] ([209.85.161.170:61373] helo=mail-gx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/81-52610-8BC10FC4 for ; Fri, 26 Nov 2010 15:46:49 -0500 Received: by gxk20 with SMTP id 20so1242553gxk.29 for ; Fri, 26 Nov 2010 12:46:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=5f4r5pkIRH81Keb+73uktW8WPl3liOO5O2/5fUKJCOs=; b=NFuD9LLAnyAs1BwJq6i+3SmXL16sXNST0nagbBosR6dFyZN7i/GowiAwkQl1PLEjwc xeUNQ6hkPxkn0XY29CYqZLqwyvBu87Y5cfDqZmpwLahBqXpslZ5EyMivMwRQ664zbxoI wneyM91sd8CbPWdCWfH0x8VQWf/pSpHisyaIw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=t9dS9SzLMa5WzN0zCyBQ89WThuqk0JqR1U3h4dCkyRhAASWM90n+nUF27eO0Eokm/s gnjOWnkoUxb2jymoCxfk6qUEoXUzAO6v/R+hXTZt1lzAYM05qtXOwz07DZI8hL+rFSwY BW9srOkAlj+Uli23AE/wGmdQ8zOrA9nkjt7Tc= Received: by 10.91.42.23 with SMTP id u23mr5040453agj.67.1290804405711; Fri, 26 Nov 2010 12:46:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.90.91.14 with HTTP; Fri, 26 Nov 2010 12:46:25 -0800 (PST) In-Reply-To: References: Date: Fri, 26 Nov 2010 21:46:25 +0100 Message-ID: To: Ferenc Kovacs Cc: Felipe Pena , internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] new foo()->bar() From: peter.e.lind@gmail.com (Peter Lind) On 26 November 2010 21:37, Ferenc Kovacs wrote: > > > On Fri, Nov 26, 2010 at 9:25 PM, Peter Lind wrot= e: >> >> On 26 November 2010 20:36, Felipe Pena wrote: >> > Hi all, >> > I'm here again to presents another proposal, which adds support for >> > instantiating a class and calling its methods and accessing its >> > properties >> > on same command. >> > >> > Example: >> > >> > > > >> > class bar { >> > =C2=A0public $x =3D 'PHP'; >> > } >> > >> > class foo extends bar { >> > =C2=A0public function bar() { >> > =C2=A0 =C2=A0return $this; >> > =C2=A0} >> > } >> > >> > var_dump(new foo()->bar()->x); // string(3) "PHP" >> > >> > ?> >> > >> > Other examples which describes the feature at >> > http://wiki.php.net/rfc/instance-method-call >> > >> > Thoughts? >> >> It seems fairly handy and I've been in situations where I wanted to do >> something like that - in fact, I use factories to achieve something >> similar. >> =C2=A0However, the more I use it, the more it feels like introducing cod= e >> smells into my code. You're essentially instantiating an object only >> to immediately throw it away. That means you don't actually need the >> object at all, you should probably be looking for static methods or >> class properties. Trying to avoid statics by introducing a way to >> instantiate and throw away objects in the same statement feels a lot >> like reinventing OOP while adding overhead. >> >> Anyway, just a personal observation. I generally favour the way that >> PHP allows you to dig your own grave (i.e. I love the freedom of the >> language), so as a developer I would probably favour this as well, >> though I find it mainly a way to introduce hacks. >> > > 1, I have to use a non-trivial library or "module" for a simple task, and= I > don't want to write 20 line of code, and introduce 4 helper variable. If it's a one-off, then I really don't see the problem. If you're facing it again, write a facade. > 2. I want to get from point 1 to point 5 but I'm not interested in the st= eps > in-between (classical method chaining), but sadly one of the steps requir= es > object=C2=A0instantiation. If it's your code, then why are you not simplifying it? What's the point of writing code that you have to go through in five steps? Why not write a wrapper method? The reasons presented sounds quite like "I want to be able write hacks easier" rather than "I want to fix an actual problem". I.e. there are solutions for this already that use OOP principles. That said, this fix may very well address other situations :) Regards Peter --=20 WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15