要实现链式操作需要在方法中 return $this,不然的话只能一个一个方法调用
//php链式操作
class lianShi
{
public $name;
public $age;
public $sex;
public function name($name)
{
$this->name = $name;
return $this;
}
public function age($age)
{
$this->age = $age;
return $this;
}
public function sex($sex)
{
$this->sex = $sex;
return $this;
}
}
$lianshi = new lianShi();
$obj = $lianshi->name('xxx')->age(18)->sex('男');
var_dump($obj);
echo $obj->name;