Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94475 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93078 invoked from network); 11 Jul 2016 19:51:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2016 19:51:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=jesseschalken@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jesseschalken@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.177 as permitted sender) X-PHP-List-Original-Sender: jesseschalken@gmail.com X-Host-Fingerprint: 209.85.223.177 mail-io0-f177.google.com Received: from [209.85.223.177] ([209.85.223.177:33576] helo=mail-io0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A3/71-17655-6B8F3875 for ; Mon, 11 Jul 2016 15:51:18 -0400 Received: by mail-io0-f177.google.com with SMTP id 38so16374589iol.0 for ; Mon, 11 Jul 2016 12:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=FcHvzfAJviGdeUTdHRSX1nD9Ird7opHax4EJkuyKdII=; b=sMAbkaxK0jb8qzJc4HrpMNz0iv9OfdqoIXRIym5jDa53H7pawy0VerbzaTwTQKtcnI 1BDc/IJk8PMJBC85PhhJu/5S07V64LdVc2U0st+0Xy47deK8ajkNmsiizWgJVLgVZSOo s8aSxUmeCT2LTmhAyKxnnXz/2T/+OYEba3rd0NknOqoR38DdzYM1Jg23x0C3L8cEoOw8 6QzqyfU9ql12TXFzW68U+A65A/oRNSxa5K1G6bhcFMIjjMbxmjRBwngBBJIa96zGS8tR F2yCyLMjahJAisHcw3eBsULI7y1pV8qEbvLwRqZZdz6slV2yfdaSn7SI4E90+wWkrSi9 0q9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=FcHvzfAJviGdeUTdHRSX1nD9Ird7opHax4EJkuyKdII=; b=JpBQGNAsJc//5xtHAgtsWVApe2H3grTOEtgqK+eLp1JiZdcCBU8r0i4TLzT/3e8w6W /PCv/kK9olOSvE1ATzsrRnUjlOQtFQJnLmB8ooLQewjUuJ8eI8rI4hm5ifJdiRLf4f3q NPkvZUGQFHwPkfeP7hdJhTVuYaUthA6D0iHTAk00Ct3eenUHcp91wXjJoyB6dwgJyau4 yQQD5+LB/k8aIBrhFmt/vCY1k6+mBY/lUdycpBPRq/unUkpxcmU1Q+st8gI0WYTWU07Q 7vOE6rKg7jY0qlzuozs4w/cLRXZ3B+1iPQns3cw/dwWQk/pLsB0hBZo89XsA8uHE/ZA/ rfjA== X-Gm-Message-State: ALyK8tKnwJbCu27HPpi8z6Y6Yi688T+r/nVqZR4G04L37BhYsapsrYQvc2ATTY3eiukUhQDfuGHg4ud1XIPqbw== X-Received: by 10.107.25.7 with SMTP id 7mr22154607ioz.104.1468266675578; Mon, 11 Jul 2016 12:51:15 -0700 (PDT) MIME-Version: 1.0 Sender: jesseschalken@gmail.com Received: by 10.79.72.7 with HTTP; Mon, 11 Jul 2016 12:51:15 -0700 (PDT) In-Reply-To: References: Date: Tue, 12 Jul 2016 05:51:15 +1000 X-Google-Sender-Auth: BeoPEWAMNZVa2bNcFzKUrZlfTaA Message-ID: To: Marco Pivetta Cc: Rasmus Schultz , Daniel Ciochiu , PHP internals Content-Type: multipart/alternative; boundary=001a113fde08a22c2c0537617928 Subject: Re: [PHP-DEV] Proposal for php7 class method return From: me@jesseschalken.com (Jesse Schalken) --001a113fde08a22c2c0537617928 Content-Type: text/plain; charset=UTF-8 On Mon, Jul 11, 2016 at 10:18 PM, Marco Pivetta wrote: > Hi Jesse, > > `return $this;` is a fairly common anti-pattern. It can be useful in few > edge-cases, like immutable APIs (CoW) and DSL builders, but it's usually a > bad idea. I ranted extensively about this at > https://ocramius.github.io/blog/fluent-interfaces-are-evil/ > I agree, but nonetheless at the cost of the problems both you (in your blog post) and I have mentioned, "return $this;" does save the verbosity of repeating a variable name, and often saves a variable altogether: $blah = new Blah(); $blah->setFoo(1); $blah->setBaz(2); $this->setBlah($blah); becomes $this->setBlah((new Blah()) ->setFoo(1) ->setBaz(2) ); Some cascade operator or inline group method call/property set achieves the same thing, but without all the problems of "return $this;": $this->setBlah((new Blah()) ->>setFoo(1) ->>setBaz(2) ); $this->setBlah(new Blah() { setFoo(1), setBaz(2), }); $this->setBlah(new Blah() { foo = 1, baz = 2, }); --001a113fde08a22c2c0537617928--