note 96738 deleted from language.oop5.overloading by danbrown

From: Date: Mon, 15 Mar 2010 16:36:33 +0000
Subject: note 96738 deleted from language.oop5.overloading by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167055@lists.php.net to get a copy of this message
Note Submitter: tom from hh ---- Singlton attempt with __callStatic: <?php class Singleton { private static $__instance = null; private function __construct() { } /** * 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) { if(!isset(self::$__instance)) { self::$__instance = new self; } return call_user_func_array(array(self::$__instance, "_" . $name), $arguments); } public function _foo($bar) { echo $bar; } } Singleton::foo("bar"); ?> while using PHP Strict Standards the underscored method calls are sadly required. Seems like the interpreter got problems overloading object calls with static calls. Any improvements/ideas?

« previous php.notes (#167055) next »