note 96419 added to function.get-class
| From: | eizdealer at no dot spam dot org | Date: | Fri, 26 Feb 2010 06:21:48 +0000 |
| Subject: | note 96419 added to function.get-class | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166389@lists.php.net to get a copy of this message | ||
Regarding the Singleton base class posted by danbettles: I think the following solution is cleaner
and more obvious.
<?php
class HS_Singleton {
protected static $instance;
protected function __construct() {
}
final private function __clone() {
}
final public static function get_instance() {
if (self::$instance===null) { $child_class = get_called_class(); self::$instance = new
$child_class; }
return self::$instance;
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 119.136.71.145
----
Manual Page -- http://www.php.net/manual/en/function.get-class.php
Edit -- https://master.php.net/note/edit/96419
Del: integrated -- https://master.php.net/note/delete/96419/integrated
Del: useless -- https://master.php.net/note/delete/96419/useless
Del: bad code -- https://master.php.net/note/delete/96419/bad+code
Del: spam -- https://master.php.net/note/delete/96419/spam
Del: non-english -- https://master.php.net/note/delete/96419/non-english
Del: in docs -- https://master.php.net/note/delete/96419/in+docs
Del: other reasons-- https://master.php.net/note/delete/96419
Reject -- https://master.php.net/note/reject/96419
Search -- https://master.php.net/manage/user-notes.php