标签:
<body> <?php //单例模式 /*class Ren { public $name; } $r = new Ren(); $r1 = new Ren(); */ class DA { public $name; static private $dx;//存放对象的变量 //将构造变为私有,外界没法造对象 private function __construct() { } //提供一个造对象的方法 static function CreateDX() { if(empty(self::$dx)) { self::$dx = new DA(); } return self::$dx; } } $d = DA::CreateDX(); $d1 = DA::CreateDX(); $d1->name = "lisi"; var_dump($d==$d1); ?> </body> </html>
标签:
原文地址:http://www.cnblogs.com/bilibiliganbei/p/5578470.html