class Foo {
     private $val = 0;
     private $pool = array();
     public function getVal($key) {
         if (!isset($this->pool[$key])) {
            $this->pool[$key] = $this->create();
         }
         return $this->pool[$key];
     }
     private function create() {
         return ++$this->val;
     }
     public function clear($key) {
         unset($this->pool[$key]);
     }
 }
 
 $f = new Foo;
 print $f->getVal(1) . "\n";  # 1
 print $f->getVal(1) . "\n";  # 1
 print $f->getVal(2) . "\n";  # 2
 print $f->getVal(1) . "\n";  # 1
 $f->clear(1);
 print $f->getVal(1) . "\n";  # 3

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS