标签:
<?php
class Single{
public static $instance = null;
//防止子类扩大权限,使外部可以new对象
final protected function __construct(){
}
public static function getInstance(){
if(self::$instance === null){
self::$instance = new self();
}
return self::$instance;
}
//防止clone
final protected function __clone(){
}
}
$s1 = Single::getInstance();
$s2 = Single::getInstance();
if($s1 === $s2){
echo "s1和s2是一个对象";
}else{
echo "s1和s2不是一个对象";
}
标签:
原文地址:http://www.cnblogs.com/shenming/p/4216723.html