当前位置:Gxlcms > PHP教程 > php入门2单例模式

php入门2单例模式

时间:2021-07-01 10:21:17 帮助过:5人阅读

单例模式:
模式:提供创建的静态方法或在构造函数中创建。常用是静态方法。
1.构造函数私有访问属性
2.静态的指向本类的指针
3.静态的创建自身的方法
以下是php中的实现,getinstall理论上应该加上线程同步,暂未写。

classmyclass{publicstatic$mydata1=NULL;
    privatefunction__construct(){echo"构造函数
"
; } publicstaticfunctiongetinstall() {if ( self::$mydata1==null) { echo"创建对象
"
; self::$mydata1 = new myclass(); } returnself::$mydata1; } publicfunctiontest() {echo"hello2
"
; } } $f = myclass::getinstall(); $f->test(); $f2 = myclass::getinstall(); $f2->test(); ?>

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介绍了 php入门2 单例模式,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

  • 人气教程排行