note 96739 deleted from language.oop5.overloading by danbrown
| From: | danbrown@php.net | Date: | Mon, 15 Mar 2010 16:28:57 +0000 |
| Subject: | note 96739 deleted from language.oop5.overloading by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167052@lists.php.net to get a copy of this message | ||
Note Submitter: tom from hh
----
Private alternative for my previous Singleton attempt:
<?php
class Singleton {
private static $__instance = null;
private function __construct() {
}
public function __clone() {
// throw Exception
}
/**
* Alternative to get rid of the isset-check in __callStatic
*
* @static
* @access public
*/
public static function setup() {
if(!isset(self::$__instance)) {
self::$__instance = new self;
} else { /** Error */}
}
public static function __callStatic($name, $arguments) {
return call_user_func_array(array(self::$__instance, "__" . $name), $arguments);
}
/**
* All internal
*
* @access private
* @param string $bar
*/
private function __foo($bar) {
echo($bar);
}
}
Singleton::foo("bar");
?>