Home > php教程 > php手册 > body text

实现PHP链式操作

WBOY
Release: 2016-06-06 20:13:58
Original
1389 people have browsed it

熟悉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...
	}
}
?>
Copy after login

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

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

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template