/**
* 單例模式實作類別-->ArrayAccess(陣列式存取)介面
*
* @author flyer0126
* @since 2012/4/27*/
class Single{
private $name;
private static $_Instance = null;
private static $_Instance = null;
}
{
靜態函數load()
{
if(null == self::$_Instance)
{
_Instance;
}
public function setName($name)
{
$this->name = $name;
}
$this->name = $name; return $這個->名稱;
}
}
$s = Single::load();$s->setName("jack");echo $s-getName (); /jack//調整一下(繼承ArrayAccess && 實作4個方法)
class Single 實作ArrayAccess
{
🜵st pri
私有函數__construct() {
}
靜態函數load()
{
if(null == self::$_Instance)
= $this
public function getName() { return $this->name; } / * 實作四個方法 * offsetExists(),用於識別一個元素是否已定義 為一個元素設定新值 * offsetUnset(),用於刪除一個元素和對應的值 *f///fid if (is_null($offset)) { $this->container[] = $value; } else s = $ } }public function offsetGet($offset)
{
return isset($this->container[$]
}public function offsetExists($offset)
{
return isset($this->container[$offset]); set)
{
unset($this->container[$offset]);
}
}
$s = Single::load ();jack
$s = Single::load ();jack
$s = Single::load ();jack
$s = Single::load ();
jack$");
$s["name"] = "mike";
單一物件
(
[name:Single:private] => jack
[container] => Array
)
)
**/