Home  >  Article  >  Backend Development  >  In fact, method chaining can also be used in PHP_PHP Tutorial

In fact, method chaining can also be used in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:23:03865browse

Just give a brief explanation:

Copy code The code is as follows:

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();


The result is as follows:
Copy code The code is as follows:

name1
name2
name3

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324583.htmlTechArticleA brief explanation: Copy the code as follows: ?php class test { private $_name = ''; public function setName ($name) { $this-_name = $name; return $this; } public function getName...
Statement:
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