I was looking at some php code and stumbled on a pipeline script. In the method to add something to the pipeline:
public function pipe(callable $stage)
{
$pipeline = clone $this;
$pipeline->stages[] = $stage;
return $pipeline;
}
The object is getting cloned, and returned. Could someone explain me the advantages of this approach, wouldn't the following code return the same results?
public function pipe(callable $stage)
{
$this->stages[] = $stage;
return $this;
}