php: 单一模型
程序代码<?php
class Singleton
{
private static $instace;
function __construct()
{
if(!self::$instace) //create it
{
self::$instace = $this;
echo 'New Instance!<br>';
}
else
{
echo 'Old Instance!<br>';
}
return self::$instace;
}
}
$s1 = new Singleton();
$s2 = new Singleton();
$s3 = new Singleton();
?>
class Singleton
{
private static $instace;
function __construct()
{
if(!self::$instace) //create it
{
self::$instace = $this;
echo 'New Instance!<br>';
}
else
{
echo 'Old Instance!<br>';
}
return self::$instace;
}
}
$s1 = new Singleton();
$s2 = new Singleton();
$s3 = new Singleton();
?>

