<?php
header("content-type:text/html;charset=utf-8");
class A{
public static $link = null;
public function __construct(){
echo '链接数据库';
}
public static function getconnect(){
if(is_null(self::$link)){
return self::$link = new A;
}else{
return self::$link;
}
}
}
$a = A::getconnect();
echo '<br>';
$b = A::getconnect();
if($a === $b){
echo 'Y';
}else{
echo 'N';
}
结果: //证明这是同一个对象。
链接数据库
Y