Proposal for php7 class method return

From: Date: Sat, 09 Jul 2016 06:47:49 +0000
Subject: Proposal for php7 class method return
Groups: php.internals 
Request: Send a blank email to internals+get-94438@lists.php.net to get a copy of this message
Hi, I have a proposal that for a given method with a return type of <self>, 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

« previous php.internals (#94438) next »