<?php
header('Content-type :text/html ; charset = utf-8');
class Person{
private $hash;
static private $p;
private function __construct(){
$this->hash = mt_rand(1,99999);
}
static public function getInstance(){
if(self::$p instanceof self){
return self::$p;
}
self::$p = new self();
return self::$p;
}
}
$p1 = Person::getInstance();
print_r($p1);
echo '<br/>';
$p2 = Person::getInstance();
print_r($p2);
echo '<br/>';
$p3 = Person::getInstance();
print_r($p3);
echo '<br/>';
?>
PHP学习:单例
