Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50601 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63622 invoked from network); 26 Nov 2010 20:52:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Nov 2010 20:52:15 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.83.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 74.125.83.42 mail-gw0-f42.google.com Received: from [74.125.83.42] ([74.125.83.42:58229] helo=mail-gw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/E1-52610-EFD10FC4 for ; Fri, 26 Nov 2010 15:52:15 -0500 Received: by gwb20 with SMTP id 20so1230391gwb.29 for ; Fri, 26 Nov 2010 12:52:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type; bh=JiK8hX2Q1sGYpyJmLbf2/+n0yFUeW4+akg8g6TT2e9U=; b=tfwNz9YCzjyDpoiEMI74GqjuLUQZR0SKplva7P+no+eR+7WqOUtKbMV064bT+7k2Pw cwEdIG3BBvLkPv713EiW2cUqMimNqBoskO0lzlk/qXjSp4KPfLWclJzljm51/0BfGfBp gkQcgAxZBKHFhzmdI+iwjwKUsPSD22mBBPhHs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=FAgXgjtWqezaz5WAshBb2+OaLC5vxkbm+Aq0NZ9jIiCt15Yl+I9UZ4fNOQYqK3A4mM z/I/uH2IkqvzHmAj6thgnzgysRW16/XpUIBMPopDf2PwTuvZE8OShWzQT5g9LXorE8aH UOsReaXYq85P5VnqiQLAJc4flMb/zCeeGRbX0= MIME-Version: 1.0 Received: by 10.91.201.8 with SMTP id d8mr3376999agq.195.1290804730806; Fri, 26 Nov 2010 12:52:10 -0800 (PST) Sender: tyra3l@gmail.com Received: by 10.90.53.4 with HTTP; Fri, 26 Nov 2010 12:52:10 -0800 (PST) In-Reply-To: References: Date: Fri, 26 Nov 2010 21:52:10 +0100 X-Google-Sender-Auth: QnZTaqWf1Cj3PkdjQ_cMtmGed5I Message-ID: To: Peter Lind Cc: Felipe Pena , internals Content-Type: multipart/alternative; boundary=0016367658a0744d680495fae5e2 Subject: Re: [PHP-DEV] [RFC] new foo()->bar() From: info@tyrael.hu (Ferenc Kovacs) --0016367658a0744d680495fae5e2 Content-Type: text/plain; charset=UTF-8 On Fri, Nov 26, 2010 at 9:46 PM, Peter Lind wrote: > On 26 November 2010 21:37, Ferenc Kovacs wrote: > > > > > > On Fri, Nov 26, 2010 at 9:25 PM, Peter Lind > wrote: > >> > >> 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 { > >> > public $x = 'PHP'; > >> > } > >> > > >> > class foo extends bar { > >> > public function bar() { > >> > return $this; > >> > } > >> > } > >> > > >> > 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. > >> However, the more I use it, the more it feels like introducing code > >> 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 > steps > > in-between (classical method chaining), but sadly one of the steps > requires > > object instantiation. > > 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. > > Sorry, I don't have the time and/or patience to fix every code out there, which I might happen to come across in a project. :) > That said, this fix may very well address other situations :) > > sure thing, I just told a(two) use-case from the top of my head. Tyrael --0016367658a0744d680495fae5e2--