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