note 49463 deleted from language.oop5.patterns by curt
| From: | curt@php.net | Date: | Thu, 03 Feb 2005 03:04:35 +0000 |
| Subject: | note 49463 deleted from language.oop5.patterns by curt | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-84408@lists.php.net to get a copy of this message | ||
Note Submitter: me at timvw dot info
----
If you are going to implement the Singleton Pattern you don't want to forget the magic __clone
method.
class Singleton
{
private static $singleton;
private function __construct()
{
echo "inside constructor method.";
}
public static function getInstance()
{
if (self::$singleton == null)
{
self::$singleton = new Singleton;
}
return self::$singleton;
}
public function __clone()
{
trigger_error('Clone is not allowed.', E_USER_ERROR);
}
}
$instance1 = Singleton::getInstance();
$instance2 = Singleton::getIntance();
$instance3 = clone($instance1);