note 62796 rejected from language.oop5.static by betz
| From: | betz@php.net | Date: | Thu, 09 Mar 2006 20:34:50 +0000 |
| Subject: | note 62796 rejected from language.oop5.static by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-105163@lists.php.net to get a copy of this message | ||
Note Submitter: mmastran at purdue dot edu
----
can anyone find the how to fix the bottom?
class Logging
{
static private $instance = false;
function __construct()
{
if (Logging::$instance) {
throw new Exception("trying to instantiate a singleton");
}
Logging::$instance = $this;
}
static function instance()
{
if(!Logging::$instance) {
Logging::$instance = new Logging();
}
return Logging::$instance;
}
}
$translated = "Logging"; // can be many other things
try {
return new $translated();
} catch (Exception $e) {
echo "$translated is a singleton<br>";
// return Logging::instance(); // works
// return $translated::instance(); // doesnt work
}