note 67958 deleted from language.oop5.patterns by danbrown

From: Date: Sun, 23 Jan 2011 16:44:04 +0000
Subject: note 67958 deleted from language.oop5.patterns by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176117@lists.php.net to get a copy of this message
Note Submitter: uvillaseca at yahoo dot es ---- I don't know if it's useful has a singleton that is a singleton only inside a script. By example, having the following scripts: <?php //index.php require_once("Singleton.php"); $p = Singleton::getInstance(); $s = Singleton::getInstance(); ?> <?php //Singleton.php class Singleton { private static $instance; private function __construct() { } public static function getInstance() { if(!isset(self::$instance)) { echo 'creating singleton'; self::$instance = new self; } return self::$instance; } } ?> Calls to index.php always returns the message 'creating singleton', so a new instance of the class is created for each call to index.php; and this is not the behaviour that I'd expect. Best regards, Ubaldo

« previous php.notes (#176117) next »