Home > Backend Development > PHP Tutorial > php单例对象形式

php单例对象形式

WBOY
Release: 2016-06-13 12:34:04
Original
878 people have browsed it

php单例对象模式

?

假设我们需要写一个类用来操作数据库,并同时满足以下要求:

①SqlHelper类只能有一个实例(不能多)
②SqlHelper类必须能够自行创建这个实例
③必须自行向整个系统提供这个实例,换句话说:多个对象共享一块内存区域,比如,对象A设置了某些属性值,则对象B,C也可以访问这些属性值(结尾的例子很好的说明了这个问题)


?转自:php?单例模式?-?神马?-?云代码空间?http://yuncode.net/article/a_524a37fc4bfb716

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