Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94460 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89428 invoked from network); 10 Jul 2016 12:31:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jul 2016 12:31:46 -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.170 as permitted sender) X-PHP-List-Original-Sender: jesseschalken@gmail.com X-Host-Fingerprint: 209.85.223.170 mail-io0-f170.google.com Received: from [209.85.223.170] ([209.85.223.170:36337] helo=mail-io0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8E/20-22463-13042875 for ; Sun, 10 Jul 2016 08:31:45 -0400 Received: by mail-io0-f170.google.com with SMTP id s93so36494696ioi.3 for ; Sun, 10 Jul 2016 05:31:45 -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=F8g1CZAnzVkp9HoTGXsf1P5olSDkCb8p0G0t2DMj21Y=; b=fgiYTET1GmY1F6nbTiWUxpqUOgmmAYhBdN4hEGZdD7rGVcaDFgh2ACLkm/jTCO8V0H HOSH9HfMJDBbP0l8fBigHYzO7/efHX2rC+1sLYVtskFFHrxz+I0lPEEoFku3s9vyzYm3 lOxY0pt8rnACMSqwAnZsA4HMkbB+c2xQ+FyiCh3I7HTqbVWLWZq+nZai59wGp4zGTavp HM5c/Hq8Px7fn1VXlZjwCleTj5XAIVqxDx6G9zp5pVz+bVKxYOW/VMEncrkZu+R4ymdU nGy3h1AD/rKJan2k6EN05Nunv27oA6renbRaHOLfanKYDlRTomS5KZVeREkekXKRlSkm CBCw== 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=F8g1CZAnzVkp9HoTGXsf1P5olSDkCb8p0G0t2DMj21Y=; b=MXOqO4VXP9V+vJgFuldCsBFcnwpXIuj1NKiBK7RcCIxpgcL8Ansq64SEMrgPAKk/kx cz+tncbUFRy1LDJUx40EWK9+pOQwgWPzl1HmUnLKBFKCO0B+2+nWIv3JS/aw2eu7BeTA ItKy+lxwCmVJGJGtawtfYJ41mGMyzvxWHdeYIaCuZNrokSPNqMqcoilFAF3lfEp7tr2K bA0+FRFZkTKuCec0+hkFaa0Q5echFp8bPBmgnOpgwGmnn8uza73Pf8ex7ZxCP+A5MFsQ njs+4+S3ovjhnzE55h+yrsrhIokrn4YxAIdPxSb9aaoelr5YhfvxrqIMzVwtP0u+uiCw JuGw== X-Gm-Message-State: ALyK8tJlbX9dX/X3WJoJLuVeLSFrW9meDjWtK2CRs1hbiOUZ5TQvecXxyhR0cw4zr5hj79axAHhG820zDaPc3w== X-Received: by 10.107.180.199 with SMTP id d190mr15114609iof.151.1468153902713; Sun, 10 Jul 2016 05:31:42 -0700 (PDT) MIME-Version: 1.0 Sender: jesseschalken@gmail.com Received: by 10.79.72.7 with HTTP; Sun, 10 Jul 2016 05:31:42 -0700 (PDT) In-Reply-To: References: Date: Sun, 10 Jul 2016 22:31:42 +1000 X-Google-Sender-Auth: TUAIb4iX84eYPMPZIJ8S9Up5_g0 Message-ID: To: Rasmus Schultz Cc: Daniel Ciochiu , PHP internals Content-Type: multipart/alternative; boundary=94eb2c06986ad8d139053747377b Subject: Re: [PHP-DEV] Proposal for php7 class method return From: me@jesseschalken.com (Jesse Schalken) --94eb2c06986ad8d139053747377b Content-Type: text/plain; charset=UTF-8 On Sun, Jul 10, 2016 at 8:34 PM, Rasmus Schultz wrote: > > What you're really trying to accomplish is something like the ".." > operator found in some other languages - this is known as the "cascade > operator" in Dart, for example: > > > http://news.dartlang.org/2012/02/method-cascades-in-dart-posted-by-gilad.html > > While I was writing about an operator to set object properties in-line here: http://news.php.net/php.internals/93662 , I considered it would be easy to add method calls to the same syntax: return Blah::create(5) { prop1 = 'hello', prop2 = a_func(), setThing(9), setOtherThing(1), }; which is in principle just an alternative syntax to as the cascade operator in Dart. I agree entirely that method chaining is just a verbose workaround for the lack of such a language feature. I've found a few problems with method chaining which this would resolve: 1. The verbosity of adding "return $this;" to all your mutator methods (Daniel Ciochiu's issue). 2. You can't return a value from a mutator method while also supporting method chaining. In theory mutator methods shouldn't need a return value (command-query separation) but in many cases they do, such as a setter which returns the previous value, a pop() method on a stack, or a delete($where) method returning the number of deleted records. 3. It is often unclear whether a method being chained is returning the same object it was called on, a copy of the object, or an instance of a different class altogether. You can work around this with careful method naming and documentation ("with.." for new instance, "set.." for same instance etc), but language-level support eliminates this issue entirely. You could really solve a whole range of problems with such a feature. --94eb2c06986ad8d139053747377b--