SoFunction
Updated on 2025-03-03

In PHP, you can actually use method chains


<?php
class test {
private $_name = '';
public function setName($name)
{
$this->_name = $name;
return $this;
}
public function getName()
{
echo $this->_name . "\n";
return $this;
}
}
$link = new test();
// Method chain
$link->setName('name1')->getName()->setName('name2')->getName()->setName('name3')->getName();