Home  >  Article  >  Backend Development  >  php单例模式,该如何解决

php单例模式,该如何解决

WBOY
WBOYOriginal
2016-06-13 12:12:431132browse

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