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 <dan...@ciochiu.ro> wrote:

> 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
>

Reply via email to