類方法返回 $this 即可實現鏈式調用:$obj->method1()->method2()。
<?php
class Xin {
function name($name) {
echo "我的名字是:$name <br/>";
return $this;
}
function age($age) {
echo "我的年齡是:$age <br/>";
return $this;
}
}
$xin = new Xin();
$xin->name("星星")->age("10000");
?>
我的名字是:星星 我的年齡是:10000