Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50598 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59795 invoked from network); 26 Nov 2010 20:37:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Nov 2010 20:37:38 -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 209.85.160.170 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: 209.85.160.170 mail-gy0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:49263] helo=mail-gy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 80/31-52610-09A10FC4 for ; Fri, 26 Nov 2010 15:37:36 -0500 Received: by gyf2 with SMTP id 2so1209885gyf.29 for ; Fri, 26 Nov 2010 12:37:33 -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=myr2g+3HPZmyhdkr3947Xi80Mj1JNmm+SexQjQgHz7g=; b=T6Y3mhLmJMjeUbBgKgqg8peuNupBHj1LaqsH37EdC6ymKs8xvn6coEwLYJy+CN0dVt NklTm6cDg1qJf111C7icp23kJ2+BVD683h81HChFytL7Qy2RhUJnRJc2QbYPPsIOAgG0 rfMizpQN4R4Plicsp761HZPkNMV34WTicKOeI= 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=tRv6LL1R+3wUp5NFvgFPYhg6Eom/DF3AuS0rk3pMWNFg9ax4V7Ml3/obfchX7wrSUu 8w86YyS5ETljwwvLRALi2f1ptaKNuFBrPlJkAD7LBWU+67EQ00W+glWsG1SMsT8XdNnW gaiYkvOgfSrGGnsJlsXBtQbC5/Bn6ni/hTPNw= MIME-Version: 1.0 Received: by 10.90.3.31 with SMTP id 31mr4997695agc.141.1290803852522; Fri, 26 Nov 2010 12:37:32 -0800 (PST) Sender: tyra3l@gmail.com Received: by 10.90.53.4 with HTTP; Fri, 26 Nov 2010 12:37:32 -0800 (PST) In-Reply-To: References: Date: Fri, 26 Nov 2010 21:37:32 +0100 X-Google-Sender-Auth: mkZ1IB7lHzaikogOF9Q3b8TKD_I Message-ID: To: Peter Lind Cc: Felipe Pena , internals Content-Type: multipart/alternative; boundary=0016363108431ab6600495fab178 Subject: Re: [PHP-DEV] [RFC] new foo()->bar() From: info@tyrael.hu (Ferenc Kovacs) --0016363108431ab6600495fab178 Content-Type: text/plain; charset=UTF-8 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. 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. Tyrael --0016363108431ab6600495fab178--