Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94439 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95916 invoked from network); 9 Jul 2016 07:04:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Jul 2016 07:04:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.54 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 74.125.82.54 mail-wm0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:36148] helo=mail-wm0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BB/98-18622-AE1A0875 for ; Sat, 09 Jul 2016 03:04:10 -0400 Received: by mail-wm0-f54.google.com with SMTP id f126so35334962wma.1 for ; Sat, 09 Jul 2016 00:04:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=APiXkVMmf2eCJCDRbmdEECagZad/zCI+xx3NZ6JFonI=; b=MS9RX0WZ7N6z4GvWgO7FHEK2xx26F45FUr1x0fhY6rZM5Go5lFANvEyOMwANNkZdxK EU1L2OT8ZEfny8ABeFDSYwKkWdDeCI5yADo2yQGghdFpQHj3OYJtT552lIdcxP9CPyeK 8FwIn9KuexRlxz6cfCj+SGBq0G0qCVRb88TtMjsvkH2Gl6T5BDXwYnh/KAPIShY9EaWs EskXGeeZH7T2ptDDfK3i3oVRhFectW5YEg+LJnwBGc/wUCClOp01of1v2PwdCb38brJ2 0uqWlQnn+y67D8m4V5Lh+ZvZENEN0zDe6DRwXNWWRU64V6zC6jitS9v54HTo29yx6GzL yw+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=APiXkVMmf2eCJCDRbmdEECagZad/zCI+xx3NZ6JFonI=; b=ID4Rspg/0LwiIMS+aC8BHsRyVSpnzPfMM0QMrkghMg5r2KpWxlg1FkT5USYOKc7Nqc Kqaw+HskfO5UNx4QfPYiEiR4X1yCd+r8THsvgterS3m5KsV58sobiFun3qXvlyPvmXju xV+kbHV9AXYAXVIxI9750y55mrzRDQo6clIYYJ8crnSvCPIjd3bQuTgiGzmPXnJ5boC+ SbXw6fMoMKOYZ+aIxQbkia/BnZWvcLN8j6brX5jve6L/xuSX5UcwvqZtQteNDMaBW9Ei ocFU1O0nvDdAkUXQmR9EdprzJeYrqmiz0vqnSneg8lJ4HYU/DZVQLeLH5r3xaWstrHO1 QyaA== X-Gm-Message-State: ALyK8tL28/8O2ei0mgxyX4cAP/603ctFp5fIsjsYeksl5Tv62y0M5DisPrFztQwH3ERbCUmk8HzQIil17m9drg== X-Received: by 10.28.203.136 with SMTP id b130mr6891831wmg.34.1468047847759; Sat, 09 Jul 2016 00:04:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.37.202 with HTTP; Sat, 9 Jul 2016 00:03:47 -0700 (PDT) In-Reply-To: References: Date: Sat, 9 Jul 2016 09:03:47 +0200 Message-ID: To: Daniel Ciochiu Cc: PHP Internals List Content-Type: multipart/alternative; boundary=94eb2c1309d67aa43405372e86d8 Subject: Re: [PHP-DEV] Proposal for php7 class method return From: ocramius@gmail.com (Marco Pivetta) --94eb2c1309d67aa43405372e86d8 Content-Type: text/plain; charset=UTF-8 Hey Daniel, I've been playing around with `self` for a while (mostly dealing with code-generators and inheritance), and what I found is that it doesn't really make sense as a type-hint, not even in interfaces. Besides the type-work to be done to do `function setValue($value) : myClass`, what is the advantage of having `self`? Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 9 July 2016 at 08:47, Daniel Ciochiu wrote: > Hi, > > I have a proposal that for a given method with a return type of , if > method does not return anything than it should it's instance. It will > reduce code by only one line, but will improve consecutive method calls. > > class myClass > { > protected $value; > > function setValue($value) : self > { > $this->value = $value; > } > > function doubleValue() : self > { > $this->value*=2; > } > > function getValue() : self > { > return $this->value; > } > } > > $calculator = new myClass(); > > $returnValue = $calculator->setValue(3) > ->doubleValue() > ->getValue(); > > echo $returnValue; > > Any return defined in the methods body would override the return of the > class instance. > > I am looking forward to your reaction. > Thank you! > > DanielCiochiu > --94eb2c1309d67aa43405372e86d8--