Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46813 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81743 invoked from network); 19 Jan 2010 17:24:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2010 17:24:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.220.225 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.220.225 mail-fx0-f225.google.com Received: from [209.85.220.225] ([209.85.220.225:54102] helo=mail-fx0-f225.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1E/4A-29385-DCAE55B4 for ; Tue, 19 Jan 2010 12:24:31 -0500 Received: by fxm25 with SMTP id 25so813172fxm.1 for ; Tue, 19 Jan 2010 09:24:26 -0800 (PST) Received: by 10.223.14.216 with SMTP id h24mr6482852faa.106.1263921866320; Tue, 19 Jan 2010 09:24:26 -0800 (PST) Received: from ?192.168.200.22? (c-98-234-184-167.hsd1.ca.comcast.net [98.234.184.167]) by mx.google.com with ESMTPS id 13sm3135192fxm.13.2010.01.19.09.24.23 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 19 Jan 2010 09:24:25 -0800 (PST) Message-ID: <4B55EABA.6040204@lerdorf.com> Date: Tue, 19 Jan 2010 09:24:10 -0800 User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Eddie Drapkin CC: internals@lists.php.net References: <4B54FC87.8070106@zend.com> <4F.56.22457.408955B4@pb1.pair.com> <4B55D850.8000604@zend.com> <68de37341001190820p486b7c31o5689ab5554b8d260@mail.gmail.com> <4B55E591.8060708@lerdorf.com> <68de37341001190918x18d4d026ie8cac60b23d59c42@mail.gmail.com> In-Reply-To: <68de37341001190918x18d4d026ie8cac60b23d59c42@mail.gmail.com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: function call chaining From: rasmus@lerdorf.com (Rasmus Lerdorf) Eddie Drapkin wrote: > On Tue, Jan 19, 2010 at 12:02 PM, Rasmus Lerdorf wrote: >> Eddie Drapkin wrote: >>> On Tue, Jan 19, 2010 at 11:05 AM, Stanislav Malyshev wrote: >>>> The second was next on my list, while the first seems to me kind of exotic - >>>> why create object only to call one method and immediately drop it? Why this >>>> method is not static then? >>> >>> Why would this imply "dropping" the object? >>> >>> This: >>> $foo = (new bar())->someSetter(); >>> Looks a lot better than this >>> $foo = new bar(); >>> $foo->someSetter(); >> The second version is much clearer. You know exactly what $foo is. In >> the shortened version you have no idea what $foo is without reading the >> code for the someSetter() method. On first glance I would assume that >> $foo would be the success/failure return of the setter and that the >> object is dropped. >> >> -Rasmus >> > > I don't think that's necessarily a fair statement to make. If you > were working within a set of guidelines, or even within just a style, > that "dictated" that setters return $this consistently across several > class (or even all of them), it wouldn't be any less clear than the > second. Assuming that you had no idea what the class did, or what > any of its methods returned, you could make the argument that the > former is less readable, but then again, if you're making wild guesses > at what methods return without reading code/documentation, you've got > bigger issues than the readability of a constructor + method call. Wild guesses? The point is that it doesn't matter what the setter returns in the longer version because we know for a fact that the return is dropped whereas it matters a lot in the shorter version and that is where most people will guess wrong. And guess what, most people don't read documentation. Trust me on this one. -Rasmus