Home > Backend Development > PHP Tutorial > PHP中其实也可以用方法链_PHP

PHP中其实也可以用方法链_PHP

WBOY
Release: 2016-06-01 12:13:49
Original
872 people have browsed it

简单示意一下:
复制代码 代码如下:
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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template