Home  >  Article  >  php教程  >  实现PHP链式操作

实现PHP链式操作

WBOY
WBOYOriginal
2016-06-06 20:13:581354browse

熟悉Jquery的同学们会经常用上 $('p').show().html('9696e.com'); 我大PHP怎么不用上此方法了。先说一下操作的核心: 返回当前对象 ?phpclass Mysql{public function where($str){# code...return $this;}public function ordery($str){# code...return $thi

熟悉Jquery的同学们会经常用上$('p').show().html('9696e.com');我大PHP怎么不用上此方法了。先说一下操作的核心:返回当前对象

<?php class Mysql
{
	public function where($str)
	{
		# code...
		return $this;
	}
	public function ordery($str)
	{
		# code...
		return $this;
	}
	public function group($str)
	{
		# code...
		return $this;
	}
	public function get()
	{
		# code...
	}
}
?>

给MYSQL类做了做一个简单的链式调用;代码很简陋,链式调用的核心在于返回的return $this; 是她帮助我们完成PHP链式操作!

转载请注明来源:新一 ? 实现PHP链式操作

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