I have a class for interacting with a memcache server. I have different functions for inserting, deleting and retrieving data. Originally each function made a call to
I think you're looking for static properties here.
class mc {
private static $instance;
public static function getInstance() {
if (self::$instance== null) {
self::$instance= new self;
}
return self::$instance;
}
private function __construct() {
$this->mem = memcache_connect(...);
}
}
This implements a basic singleton pattern. Instead of constructing the object call mc::getInstance()
. Have a look at singletons.