简单示意一下:
实现代码如下:

<?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();
// 方法链
$link->setName('name1')->getName()->setName('name2')->getName()->setName('name3')->getName();


结果如下:
实现代码如下:

name1
name2
name3

以上就是【PHP中其实也可以用方法链】的全部内容了,欢迎留言评论进行交流!

赞(0) 踩(0)
发表我的评论

最新评论

  1. 暂无评论